过滤时间比...更早在django?

时间:2009-12-31 07:18:08

标签: django

def get_filter_result(self, customer_type='',last_contact_filled='', tag_selected='', city_selected=''):
        qdict = {}
        if customer_type != '':
            qdict['type__name'] = customer_type
            qdict['active']=True
        #MY PROBLEM IS HERE get result that older than last_contact_filled day(s)
        if last_contact_filled != '':
            for day_filter in xrange(1,int(last_contact_filled)+1):
                qdict['last_contact__day']=day_filter
            #qdict['last_contact']=last_contact_query
        if tag_selected != '':
            idtag = tag_selected.split(',')
            qdict['tag__id__in']=idtag
        if city_selected != '':
            idcity = city_selected.split(',')
            qdict['city__id__in']=idcity
        queryset = Customer.objects.filter(**qdict)

last_contact_filled用户输入的值。

last_contact = forms.IntegerField(widget = forms.TextInput(attrs={'size': '2'}),help_text='day(s)')

例如,如果用户输入33将获得last_contact早于33天的结果

1 个答案:

答案 0 :(得分:1)

here。只需适当修改timedelta()参数。