On Fri, 2007-11-02 at 12:07 +0100, Simone Cittadini wrote:
> Malcolm Tredinnick ha scritto:
> > On Fri, 2007-11-02 at 11:25 +0100, Simone Cittadini wrote:
> >>
> >> 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).
> >
> > 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).
> >   
> 
> I think I'm in need of a for dummy example here ...
> 
> in the view code :
> 
> def list_filters(request):
>     [...]
>     else:
>         form = FormFilters()
>         form.filter_name.choices = [(f.name, f.name) for f in 
> Filter.objects.all()]
>         return render_to_response('list_filters.html', locals(), 
> RequestContext(request, {}))
> 
> gives :
> 
> AttributeError - 'FormFilters' object has no attribute 'filter_name' ....

The fields aren't attributes on the forms. They are contained in an
attribute called "fields", which is a dictionary. So try

        form.field['filter_name'].choices = ...
        
Regards,
Malcolm

-- 
If it walks out of your refrigerator, LET IT GO!! 
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