如何在表单中使用django_select2

时间:2019-04-09 10:51:23

标签: django django-forms django-templates

我有一个ModelChoiceField,它确实很大,所以我想使用ModelSelect2Widget过滤我的ModelChoiceField中的选择。我用了这段代码,但他没有工作 我想要这样 https://www.drupal.org/files/project-images/select2.png 这是我的代码

class Ajout4 (forms.Form):

client=forms.ModelChoiceField(queryset=Suivre.objects.all(),widget=ModelSelect2Widget(model=Suivre,search_fields=['numcniF'],dependent_fields={'numcniF': 'numcniF'},max_results=500,))
montant=forms.FloatField(required=True,widget=forms.NumberInput(attrs={'placeholder':'Paye MTN '}))

myhtml

<form method="post">
<div class="container">
<div>{% load crispy_forms_tags %}

 {% csrf_token %}
 {{con|crispy}}

 <button type="submit" class="btn btn-success" > SAVE</button>
      <button type="reset" class="btn btn-danger">RESET</button>

0 个答案:

没有答案