Всем привет, пишу поиск-фильтр на страничке, написал форму, вьюху, добавил форму на шаблон, однако нету полей, вот моя вьюха:
class ManageBranchView(ListView):
model = Branches
form_class = SearchFiliatesForm
template_name = 'branches/manage.html'
def get_form_kwargs(self, **kwargs):
kwargs = super(ManageBranchView, self).get_form_kwargs(**kwargs)
kwargs['request'] = self.request
return kwargs
def queryset(self):
#import pdb; pdb.set_trace()
try:
owner = self.kwargs['owner']
phone = self.kwargs['phone']
region_choice = self.kwargs['region_choice']
except:
owner = ''
phone = ''
region_choice = ''
if region_choice:
filiates_list = Branches.objects.filter(pid=self.request.user.organization).filter(name__icontains=owner).filter(phone__icontains=phone).filter(regions__in=region_choice)
else:
filiates_list = Branches.objects.filter(pid=self.request.user.organization).filter(name__icontains=owner).filter(phone__icontains=phone)
return filiates_list
форма:
class SearchFiliatesForm(forms.ModelForm):
region_choice = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, required=False)
def __init__(self, request, *args, **kwargs):
self.request = request
super(SearchFiliatesForm, self).__init__(*args, **kwargs)
self.fields['region_choice'].choices =self.request.user.organization.organizationtoregion_set.all().values_list('region__id')
class Meta:
model = Branches
fields = ['regions','owner','phone']
и сам шаблон:
<h3>search form:</h3>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}<br>
<input type="submit" value="search" />
</form>
Кто подскажет в чем проблема?