Add a restriction in standard Django Adminke



  • There's a laser adminke, they're entitled to add and edit materials. However, when a laser with these rights enters the materials, he will see all the materials there, both his and his.

    How do we make every laser see only his materials he added? So you could edit, too, only yours.

    The table has a field. user_id(Foreign Keys - User)I mean, every material knows who made it.



  • You need to look towards the method. queryset Class ModelAdmin:

    class MyModelAdmin(admin.ModelAdmin):
        def queryset(self, request):
            qs = super(MyModelAdmin, self).queryset(request)
            if request.user.is_superuser:
                return qs
            return qs.filter(author=request.user)
    

    https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.queryset


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2