List Info

Thread: Limiting choices in a generated form




Limiting choices in a generated form
country flaguser name
United States
2007-02-28 11:00:45
Hi all,

I am trying to limit choices on a form generated by
form_for_model. I
created a form class using form_for_instance then inherit
another
class from that and limit the list of choices for a field in
the
__init__(). I feel that I am close but I couldn't manipulate
the
choices.

My classes are as follows:

class AlbumFormForModel(forms.form_for_model(Album)):
    pass

class AlbumForm(AlbumFormForModel):
    def __init__(self, data = None):
        AlbumFormForModel.__init__(self, data)
        # do something to manipulate
self.fields['artist'].choices
here


As can be seen from the classes, AlbumForm has a list of
Artists,
which is a query set. But I couldn't manipulate this set and
reassign
it to the choices. I tired things like:

self.fields['artist'].choices.queryset =
self.fields['artist'].choices.queryset.filter(name =
'john')

but this doesn't seem to affect the queryset.

Regards and thanks for any help...
oMat


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )