如何在使用django-filters时处理(在列中添加所有值)查询集

时间:2015-02-13 13:09:45

标签: python django django-filter

filters.py

import django_filters
from adfilters.models import Product
from django.contrib import admin

class ProductFilter(FilterSet):
   price = NumberFilter(lookup_type = 'lte')
   description=CharFilter()
   release_date=DateRangeFilter()
   class Meta:
      model = Product
      fields = {'price':['lte','gte'] }

models.py

from django.db import models

# Create your models here.
class Product(models.Model):
    name = models.CharField(max_length=255,blank=True,null=True)
    price = models.IntegerField(blank=True,null=True)
    description = models.TextField(blank=True,null=True)
    release_date = models.DateField(blank=True,null=True)

views.py

from django_filters.views import FilterView
from adfilters.filters import ProductFilter,DateRangeFilter
from .models import Product
from django.http import HttpResponse
from django.template import RequestContext,loader
#from crm.search import *
from mysite.search import *
from django.conf.urls import patterns,url

import django_filters

def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

def product_list(request):
    f = ProductFilter(request.GET, queryset=Product.objects.all())
    fd = DateRangeFilter(request.GET, queryset=Product.objects.all())

这些是我的模型,视图和filter.py文件。

我希望获得特定过滤条件的总价格。

假设我搜索记录价格> 12 ,我得到 3条记录。我需要知道所显示记录的所有价格总和。

如何在使用django-filters时处理此类操作?

0 个答案:

没有答案