On Apr 24, 4:44 am, nickloman <[EMAIL PROTECTED]> wrote:
> class MyForm(forms.Form):
> def __init__(self, user, data=None):
> forms.Form.__init__(self, data)
>
> self.fields['my_options'] =
> ModelChoiceField(queryset=SomeModel.objects.get_users_objects(user))
You're on the right track. I have two suggestions. Since you're
subclassing, make a call to super() and remove the non-standard
arguments before passing them along to super()::
class MyForm(forms.Form):
def __init__(self, *args, **kwargs):
user = kwargs.pop('user', '')
super(MyForm, self).__init__(*args, **kwargs)
if user:
self.fields['my_options'] = ModelChoieField...
Now that ModelForms exist and they can have access to things like
``self.instance.user`` I don't use the above quite as much, but it's
still very useful for non-ModelForms.
- whiteinge
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---