Hello django users,
I'm trying to override the __init__ method in forms.py for an
application that extend the admin site.
I'm doing this to initialize a ModelChoiceField of the form with user
logged in, informations, so I'm trying to retrieve the user in my
__init__ method... but I think I'm missing something :)
So my code is the following (python 2.6.2/django 1.1):
class InscriptionForm(forms.ModelForm):
equipe = forms.ModelChoiceField(queryset=Equipe.objects.all(),
required=False )
def __init__(self, *args, **kwargs):
super(InscriptionForm, self).__init__(*args, **kwargs)
try:
user = kwargs.get('user')
if user.get_profile().evenement:
self.fields['equipe'] = forms.ModelChoiceField
(queryset=Equipe.objects.filter(evenement=user.get_profile
().evenement), required=False )
else:
self.fields['equipe'] = forms.ModelChoiceField
(queryset=Equipe.objects.all(), required=False )
except:
self.fields['equipe'] = forms.ModelChoiceField
(queryset=Equipe.objects.all(), required=False )
My issue is that I never put explicitly the user in the call of the
__init__. I supposed that is the admin internal mechanism that do the
stuff, but I can't figure out where... so my kwargs.get('user') return
nothing, that is pretty obvious.
So my question is : how to retrieve the user logged in an AdminForm
element???
Thx guys.
Julien.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---