On Jan 2, 9:48 am, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote:
> On Dec 30 2007, 6:46 pm, makebelieve <[EMAIL PROTECTED]> wrote:
>
> > Part of a form of mine has a drop down to choose a region which is a
> > foreign key to the object I'm updating.  Further, I have a link to add
> > a new region if the user does not see what they want.  If a user adds
> > a new region it is successfully made in the database, but it will not
> > show up in the drop down until I restart my web server.  Is there a
> > way around this?
>
> The problem you're having is usually referred to as import-time vs.
> execution-time, and is definitely worth reading up on as you're
> starting to learn Python. What is happening is the for-loop is only
> being run one time as Python is starting up (which affects long-
> running Python processes such as the one started by Apache, for
> example). A simplified explanation is that your class is being defined
> in memory as Python starts-up and the region_choices value is
> essentially hard-coded for the duration. You can get around this by
> putting your for-loop in a method, since it will be re-run every time
> the method is called.
>
> Fortunately, Django has an even better solution for what you're trying
> to do: use a ModelChoiceField instead -- it'll handle all that
> ForeignKey business for you automatically. It not currently
> documented, but you can find example usage here [1] (use your
> browser's find).
>
> .. [1]http://www.djangoproject.com/documentation/models/model_forms/
>
> Cheers.
> - whiteinge

Sweet, thanks for the info.
--~--~---------~--~----~------------~-------~--~----~
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