Hi,

I agree excluding it from the form is the way to go and setting it in one 
of the save_* methods.

But, couldn't you also do _both_ of your methods :)

Collin

On Wednesday, December 10, 2014 3:38:48 AM UTC-5, Akshay Mukadam wrote:
>
> Hi,
> I just want to show the current logged in user in for foreign key in 
> Django admin. Following are the approach used buy me:
>
> 1-> def formfield_for_foreignkey(self, db_field, request, **kwargs):
>         if db_field.name == "user":
>             "set the current user as a default value for drop down"
>             kwargs["initial"] = request.user.id 
>         return super(ResponseAdmin, 
> self).formfield_for_foreignkey(db_field, request, **kwargs)
>
> 2->def formfield_for_foreignkey(self, db_field, request, **kwargs):
>         if db_field.name == "user":
>             "Filter the drop down as per standard procedure"
>             kwargs["queryset"] = User.objects.filter(username = 
> request.user.username)
>         return super(ResponseAdmin, 
> self).formfield_for_foreignkey(db_field, request, **kwargs)
>
> Problems for 1st approach is the current logged in user gets properly set 
> but it also shows the other users in the existing database. That is 
> actually wrong because the current user may select the other user name and 
> post the data in  admin.
>
> Problem for second appraoch(For my Team Manager not me) the only logged in 
> user gets populated and user has to select his name. He is unagreed with 
> this scenario neither ok with the 1st solution(neither me).
>
> Is there any other way to solve this
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c29a036-1d18-4a59-93e2-bf844b2e807a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to