Hello again, sorry to answer to my own mail but I can't find a way to
resolve my problem.

So, the question is very simple :
How, in an admin Form, access to the current user?

any idea?

thx

Julien.

On 18 août, 10:45, Julienoune <[email protected]> wrote:
> Hello django users,
>
> I'm trying tooverridethe__init__method in forms.py for an
> application that extend theadminsite.
> I'm doing this to initialize a ModelChoiceField of theformwith 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 theadmininternal 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to