drop down multi checkbox with bootstraps selet

142 views
Skip to first unread message

ايهاب توفيق

unread,
Mar 18, 2017, 12:58:07 PM3/18/17
to Django users

I am tring to create drop down checkbox with values from database   in my templet using bootstrap select and form MultipleChoiceField like this

 

Html

select class="selectpicker" multiple>

    {% for topping in form.the_topping %}

    <option value="{{ topping }}">{{ topping.topping_id }}</option>

 

    {% endfor %}

</select>

 

<script type="text/javascript">

$(document).ready(function() {

      $('.selectpicker').selectpicker({

    style: 'btn-info',

    size: 4

        });

                                });

</script>

Form.py

class ProfileForm(forms.ModelForm):
    the_topping = forms.ModelMultipleChoiceField(
queryset=Topping.objects.all(), required=False, widget=forms.CheckboxSelectMultiple)

   
class Meta:
        model = Pizza
        exclude = [
'user']

 

the bootstrp working and the form is working but doesnot combined

 

can any one help me PLS

Camilo Torres

unread,
Mar 18, 2017, 9:33:54 PM3/18/17
to Django users
Hi,

You have to properly construct the <select> element.

Take a look at these sections of the manual:

https://docs.djangoproject.com/en/1.10/topics/forms/#rendering-fields-manually

https://docs.djangoproject.com/en/1.10/topics/forms/#looping-over-the-form-s-fields

Take a special look at field html_name; you should be using that as the name of your select element. The name is used to map the posted data to the form in the code.

Camilo.

ايهاب توفيق

unread,
Mar 20, 2017, 2:58:14 PM3/20/17
to Django users
thank you for your help

manikanta katikam

unread,
Dec 10, 2018, 7:47:11 AM12/10/18
to Django users
can u plese send this code 
Reply all
Reply to author
Forward
0 new messages