On Fri, 2007-11-02 at 11:25 +0100, Simone Cittadini wrote:
> Stripping down my app to what isn't working as expected I have :
> 
> models :
> 
> class Filter(models.Model):
>     name = models.CharField()
>     object = models.ManyToManyField(Object)
> 
> class Object(models.Model):
>     name = models.CharField()
>     [...]
> 
> forms :
> 
> class FormFilters(forms.Form):
>     filter_name = forms.ChoiceField(choices = [(f.name, f.name) for f in 
> Filter.objects.all()])
> 
> 
> One view lists all the objects given the POST of FormFilters, but if I 
> delete/add a Filter object (from my apps interface or the automagic 
> admin one) the choices in FormFilter won't change, it remains stuck with 
> values in the db found when the engine is started (manage runserver or 
> apache mod_python).

That's expected behaviour. The query is executed *once*, when the
filter_name line is first executed by Python, which  means at import
time, is the FormFilters class is at the top level.

If you want to update the choices dynamically, you will need to assign
to filter_name.choices just before rendering it (and that's perfectly
legal to do; 'choices' is a writable attribute).

Regards,
Malcolm

-- 
Despite the cost of living, have you noticed how popular it remains? 
http://www.pointy-stick.com/blog/


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