How can I MODIFY django to create “view” permission?

后端 未结 6 1379
小鲜肉
小鲜肉 2020-12-12 15:02

I\'ve recently started using django to administer a large existing application that was grown organically over the years using twisted.web. I started experimenting with dja

6条回答
  •  悲&欢浪女
    2020-12-12 15:51

    This snippet will make superuser the only one with write access.

    class AdminOwn(admin.ModelAdmin):
        def get_readonly_fields(self, request, obj=None):
            if request.user.is_superuser:
                return self.readonly_fields
            #get all fields as readonly
            fields = [f.name for f in self.model._meta.fields]
            return fields
    

提交回复
热议问题