Re: How to use dynamic choice in a ChoiceField

2008-06-26 Thread M.Ganesh
mwebs wrote: > Thanks Nathaniel, > > but where and how do I pass the Queryset? From my view? > I am sorry but I dont understand completly > > class MyModelChoiceField(forms.ModelChoiceField): > def label_from_instance(self, obj): > return "My Object #%i" % obj.id > > > class PictureFor

Re: How to use dynamic choice in a ChoiceField

2008-06-26 Thread M.Ganesh
mwebs wrote: > Hello, > > I am trying to do something like this > > class PictureForm(forms.Form): > image = forms.ImageField(label='Picture') > gallery= forms.ChoiceField(Gallery.objects.all()) > > this just works fine, but I only want to pass several Galleries to the > C

Re: How to use dynamic choice in a ChoiceField

2008-06-26 Thread mwebs
Thanks Nathaniel, but where and how do I pass the Queryset? From my view? I am sorry but I dont understand completly class MyModelChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): return "My Object #%i" % obj.id class PictureForm(forms.Form): image

Re: How to use dynamic choice in a ChoiceField

2008-06-26 Thread Nathaniel Whiteinge
On Jun 26, 7:53 am, mwebs <[EMAIL PROTECTED]> wrote: > gallery = forms.ChoiceField(Gallery.objects.filter( ...)) You want to use a ModelChoiceField [1] instead of a ChoiceField. It takes a QuerySet as an argument:: class PictureForm(forms.Form): ... gallery = forms.ModelChoic

Re: How to use dynamic choice in a ChoiceField

2008-06-26 Thread phillc
model choice field http://www.djangoproject.com/documentation/newforms/#fields-which-handle-relationships On Jun 26, 9:53 am, mwebs <[EMAIL PROTECTED]> wrote: > Hello, > > I am trying to do something like this > > class PictureForm(forms.Form): >     image          = forms.ImageField(label='Pict

How to use dynamic choice in a ChoiceField

2008-06-26 Thread mwebs
Hello, I am trying to do something like this class PictureForm(forms.Form): image = forms.ImageField(label='Picture') gallery= forms.ChoiceField(Gallery.objects.all()) this just works fine, but I only want to pass several Galleries to the ChoiceField... something like: