Field Level Permission Django

前端 未结 3 2015
一整个雨季
一整个雨季 2021-02-05 20:27

Today i came up with a requirement where i need to implement field level permission so looking for the best possible way.

class ABC(models.Model):
    fiel         


        
3条回答
  •  爱一瞬间的悲伤
    2021-02-05 21:10

    You can also override readonly_fields in changeform_view.

    Try this in admin.py

    class ABCAdmin(admin.ModelAdmin):
    
        def changeform_view(self, request, *args, **kwargs)
            self.readonly_fields = list(self.readonly_fields)
            if request.user in group:  #or another condition
                self.readonly_fields.append('field2')
    
            return super(ABCAdmin, self).changeform_view(request, *args, **kwargs)
    

提交回复
热议问题