On Sun, 2009-05-17 at 10:41 -0700, Bobby Roberts wrote: > from django import forms > from django.contrib.auth.models import User > > # pull a recordset of the users > userdata = User.objects.all() > > def myuserlist(self): > for i in userdata: > self[i.id]='%s %s' %(i.first_name,i.last_name) > return self.items() > > #used to post messages to oher users > class FrmIdMessage (forms.Form): > posted_to = forms.ChoiceField > (required=True,widget=forms.CheckboxSelectMultiple(attrs= > {'class':'optchecklist'},choices=myuserlist(userdata))) > message = forms.CharField (max_length=300, required=True, > widget=forms.Textarea(attrs={'class':'smallblob'}))
I think you are looking for ModelMultipleChoiceField. Example: >>> from django import forms >>> from django.contrib.auth.models import User >>> >>> class MessageForm(forms.Form): ... users = forms.ModelMultipleChoiceField( ... queryset=User.objects, ... widget=forms.CheckboxSelectMultiple, ... required=True) ... >>> User(username='sdc').save() >>> User(username='bobby').save() >>> >>> print MessageForm(auto_id=False) <tr><th>Users:</th><td><ul> <li><label><input type="checkbox" name="users" value="1" /> sdc</label></li> <li><label><input type="checkbox" name="users" value="2" /> bobby</label></li> </ul></td></tr> >>> For formatting the select list, see today's thread 'Formatting a Foreign key combo box'. sdc --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---