代码语言:javascript复制
class AnchorBindAgentAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
"""
Hook for specifying custom readonly fields.
"""
# 本想用 path 里的 add 来判断
print(request.path)
# 根据 obj 是否为空来判断
if obj:
self.readonly_fields = ["agent", "anchor"]
else:
self.readonly_fields = []
return self.readonly_fields