Brilliant.  I actually looked at that page for some help with a
different form, but I guess I completely missed the part about the
init method.  Thank you so much for your help.

Adam

On Sep 11, 12:04 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Thu, Sep 11, 2008 at 12:39 AM, adam <[EMAIL PROTECTED]> wrote:
>
> > Hi everyone,
>
> > So I have a problem here.  I have a series of forms to allow someone
> > to create recipes, and I decided to build them with Django's form
> > objects.  The issue is that newly saved data doesn't appear as an
> > option on another form that I bring in as part of a ChoiceField.  An
> > example that I will provide relevant code for is someone fills out a
> > form to add a new IngredientType.  They save and all is well (it goes
> > in the DB and everything).  However, when I go to the Ingredient form
> > which has all IngredientTypes in a dropdown, the new type isn't listed
> > (although old ones are).  The data doesn't appear until I restart my
> > development server.
>
> > Here's the relevant code:
>
> > From forms.py:
>
> > class IngredientForm(forms.Form):
> >    title = forms.CharField(max_length=50,
> >                            widget=forms.TextInput(attrs=attrs_dict),
> >                            label=_(u'Ingredient Name'))
> >    type = forms.ChoiceField(choices=chain([('',
> > 'Type')],IngredientType.objects.values_list('id', 'type')),
> >                             label=_(u'Ingredient Type'))
>
> [snip]
>
> You've set the choices for the type field in the declaration of the Form
> itself, this code only gets executed once when the containing file is
> loaded.  You need to move the setting of choices to a place where it will be
> evaluated each time a new form instance is created, such as the form's
> __init__ method.  For an example look here:
>
> http://www.pointy-stick.com/blog/2008/01/06/django-tip-complex-forms/
>
> (That covers more than you're looking for here, I think, but does include an
> example of how choices can be set in __init__)
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to