Answer the question
In order to leave comments, you need to log in
Django how to display object only after filtering?
Hello, I need your help. In this code, all objects from the model are displayed on the page, there is a form by which they are filtered. It is necessary for me that all objects are not initially displayed, but appear only after filtering.
views.py
def abonstat(request):
abons = Uslugi.objects.all()
abform = AbonStatForm(request.GET)
if abform.is_valid():
if abform.cleaned_data['client']:
abons = abons.filter(client_id=abform.cleaned_data['client'])
return render(request, 'clients/abonstat.html',
{'abons': abons, 'abform': abform})
Answer the question
In order to leave comments, you need to log in
?
def abonstat(request):
abons = {}
abform = AbonStatForm(request.GET)
if abform.is_valid():
if abform.cleaned_data['client']:
abons = Uslugi.objects.filter(
client_id=abform.cleaned_data['client'])
return render(request, 'clients/abonstat.html',
{'abons': abons, 'abform': abform})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question