Django disable editing (but allow adding) in TabularInline view

前端 未结 4 2230
小鲜肉
小鲜肉 2021-02-19 23:40

I want to disable editing ALL objects within a particular TabularInline instance, while still allowing additions and while still allowing editing of the parent model.

I

4条回答
  •  粉色の甜心
    2021-02-19 23:48

    User django admin build in function has_change_permission() and return false to restrict object Edit view.

    class SuperviseeAdmin(admin.TabularInline):
      model = Supervisee
    
      def has_change_permission(self, request):
          return False
    
    class SupervisorAdmin(admin.ModelAdmin):
      inlines = [SuperviseeAdmin]
    
    admin.site.register(Supervisor, SupervisorAdmin)
    

提交回复
热议问题