Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to filter model objects in a form?
I have forms.py:
camera = Camera.objects.all()
TEST_CHOICES = [[x.id, 'Камера ' + str(x.number)] for x in camera]
class ZayavkaForm(forms.Form):
name = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=TEST_CHOICES)
def zayavka_view(request, adress_slug):
adress = Adress.objects.get(slug=adress_slug)
cameras_of_adress = Camera.objects.filter(adress=adress).order_by('-number')
context = {
'adress' : adress,
'cameras_of_adress' : cameras_of_adress,
}
return render(request, 'z.html', context)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question