django - how I can load a model to multipleChoiceField -


please y have been trying show table in form, have not been able do. please clone , create database , run project on github. code paste here.

github: https://github.com/mattisbmx/django-multiplechoicefield

model:

from django.db import models multiselect.fields import manytomanyfield  class choice(models.model):     choice = models.charfield(max_length=15)      def __unicode__(self):         return self.choice  class samplemodel(models.model):     name = models.charfield(max_length=15)     funciones = manytomanyfield(choice)     passwd = models.textfield()     def __unicode__(self):         return unicode(self.pk) 

view:

def index(request):     data = {'form': forms.selectform()}      return render_to_response("multiselect/index.html", data,                           context_instance=requestcontext(request 

form:

class selectform(forms.form):     data = (('1', 'one'), ('2', 'two'), ('3', 'three'), ('4', 'four')) #<--i think here load data model     choices = multiplechoicefield(choices=data) 

thanks

you can use modelmultiplechoicefield

class selectform(forms.form):     choices = forms.modelmultiplechoicefield(queryset=choice.objects.all()) #replace queryset queryset of choice. 

if wish change default widget

you can use widget=checkboxselectmultiple() or whichever wish.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -