On Jun 15, 1:58 pm, "./ed" <[EMAIL PROTECTED]> wrote:
> ## forms.py
> class aForm(forms.Form):
>          choicelist = [(obj.id,obj.myfield)  for obj in
> aModel.objects.all()]
>          mod = forms.ChoiceField(choice=choicelist)
>
> that's not exactly the code because the choice list is computed in
> another python file.
>
> the problem is that when i add an entry to the aModel table it does
> not update in the form (even with various reload scheme)
> it does update when I 'touch' the python file. So my guess is the
> problem lies in the 'compilation' chain or something like that.
>
> As anyone an idea how I can fix this problem because I can't allow
> users to 'touch' the python files
>
> Thanks
>
> ./ed

What's happening is that in your code, Django is working out the
options at compile time. To make them dynamic, put the code in the
__init__ method of the form - that way they'll be computed each time
the form is instantiated.

However, you may find that an easier option is to use a
ModelChoiceField rather than a basic ChoiceField:

def myForm(forms.Form):
    mod = ModelChoiceField(aModel.objects.all())

See http://www.djangoproject.com/documentation/newforms/#modelchoicefield

--
DR.
--~--~---------~--~----~------------~-------~--~----~
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