django admin view and edit only what the user has create

787 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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)