Reputation: 3791
I have different models like this for example:
class Post(models.Model):
title = models.CharField(max_length=50)
user = models.ForeignKey(User)
...
All my model have a foreign key on user. Is there a way in the django admin to see only post the user have create and edit them? Or should I do my own custom admin?
Upvotes: 3
Views: 783
Reputation: 3791
Thanks to Daniel Roseman, there is an example in the doc. Here what do I have to add to my Postadmin model.
def get_queryset(self, request):
qs = super(PostAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
return qs.filter(user=request.user)
Upvotes: 2