1

I have following problem:

In my forms.py i have following line in class:

date_from = forms.DateField(label='date', initial='1800-01-01', widget=SelectDateWidget(years=[y for y in range(1450,2050)])) 

In template i can choose the concrete date. This parameter i want to transfer to my view.py file to the following method:

def adv_search(request):
    objects = None
    if request.GET.get('key'):
        form = AdvancedSearchForm(request.GET)
        if form.is_valid():
            repo = Repository()
            objects = list(repo.find_objects(date__gt='2012-07-23'))                            
        return render(request, 'templates/adv_search.html', {'form': form, 'objects': objects })
    return render(request, 'templates/adv_search.html', {'form': AdvancedSearchForm(), 'objects': objects})

In objects = list(repo.find_objects(date__gt='2012-07-23')) i have date__gt with concrete Date.

How i can add to date__gt the date from form.Date.Field ?

Thanks.

4

1 回答 1

1

它在form.cleaned_data

您可以通过以下方式访问它:

objects = list(repo.find_objects(date__gt=form.cleaned_data['date_from']))  

这是假设您的表单声明类似于:

class AdvancedSearchForm(forms.Form):
    date_from = forms.DateField(...) 
    ...
于 2013-08-23T10:35:08.823 回答