Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 检查列值并操作表2_Django_Django Templates_Django Tables2 - Fatal编程技术网

Django 检查列值并操作表2

Django 检查列值并操作表2,django,django-templates,django-tables2,Django,Django Templates,Django Tables2,我第一次使用djangotables2。我已成功显示一个表,该表 是一个口述记录列表,其中的键和值是从我的 项目数据库 我有一个要求,我必须检查一列的值,并改变背景颜色,如css或应用引导徽章 样本代码:- views.py data_list = [] #search query = request.GET.get('q') if query: user_list = UserProfile.objects.filter(user__email__icontains=query) el

我第一次使用djangotables2。我已成功显示一个表,该表 是一个口述记录列表,其中的键和值是从我的 项目数据库

我有一个要求,我必须检查一列的值,并改变背景颜色,如css或应用引导徽章

样本代码:-

views.py

data_list = []
#search
query = request.GET.get('q')
if query:
    user_list = UserProfile.objects.filter(user__email__icontains=query)
else:
    user_list = UserProfile.objects.order_by("-user__date_joined")
for userprofile in user_list:
    data_list.append({'user_id': userprofile.id,
                      'first_name': userprofile.user.first_name,
                      'last_name': userprofile.user.last_name,
                      'address': get_city(userprofile),
                      'dateofbirth': userprofile.dateofbirth,
                      'anniversary': "NA",
                      'number_of_orders':
                      get_total_orders(userprofile),
                      'total_revenue': get_total_revenue(userprofile),
                      'highest_order': get_higest_order(userprofile),
                      'registration_date':
                      userprofile.user.date_joined.date().strftime("%B %d %Y"),
                      'last_order_date': get_last_order(userprofile),
                      'last_order_to_present_day_differene':
                      get_difference_from_last_order(userprofile)
                    })
data = ThemedCRMTable(data_list, prefix="3-")
RequestConfig(request, paginate={"per_page": 15}).configure(data)
tables.py

class CRMTable(tables.Table):
    user_id = tables.Column()
    first_name = tables.Column()
    last_name = tables.Column()
    address = tables.Column()
    dateofbirth = tables.Column()
    anniversary = tables.Column()
    number_of_orders = tables.Column()
    total_revenue = tables.Column()
    highest_order = tables.Column()
    registration_date = tables.Column()
    last_order_date = tables.Column()
    last_order_to_present_day_differene = tables.Column()


class ThemedCRMTable(CRMTable):
    class Meta:
        attrs = {'class': 'paleblue'}
模板

{% load static %}
{% load render_table from django_tables2 %}

<!doctype html>
<html>
  <head>
    <title>CRM Report</title>
    <link rel="stylesheet" href="/static/report/css/screen.css" />
    <link href="{% static 'css/bootstrap.css' %}" rel="stylesheet">
    <script src="{% static 'js/jquery.js' %}"></script>
    <script src="{% static 'js/bootstrap.min.js' %}"></script>
  </head>
  <body>
    <div class="container">
        <div class="row" style="margin-top:2%;text-align:center;">
            <form class="form-search pull-left">
              <div class="input-append">
                <input type="text" class="span4 search-query" name="q">
                <button type="submit" class="btn">Search</button>
              </div>
            </form>
            <strong style="font-size:20px;">CRM Report</strong>
            <a class="btn btn-inverse pull-right offset1" href="/">
              <span><i class="icon-step-backward icon-white icon-alignment"></i></span>
              Go Back
            </a>
            <a class="btn btn-success pull-right offset1" href="{% url generate_crm_report_csv %}">
              <span><i class="icon-download icon-white icon-alignment"></i></span>
              CRM Report
            </a>
          </div>
        {% render_table data_list %}
      </div>  
  </body>
</html>
{%load static%}
{%load render_Tables from django_Tables 2%}
客户关系管理报告
搜索
CRM报告
{%render\表数据\列表%}
问题:-

我想使单元格背景为红色,其中最后一列last\u order\u to\u present\u day\u difference的值大于30