代码之家  ›  专栏  ›  技术社区  ›  wogsland

使django管理中的日志项的内容类型为只读

  •  1
  • wogsland  · 技术社区  · 7 年前

    在我的 admin.py 我有

    class LogEntryAdmin(admin.ModelAdmin):
        readonly_fields = (
            'user', 'content_type_id', 'object_id', 'object_repr',
            'action_flag', 'change_message'
        )
    
        def has_add_permission(self, request, obj=None):
            return False
    
        def has_delete_permission(self, request, obj=None):
            return False
    

    admin.site.register(LogEntry, LogEntryAdmin)
    

    当我发现 'user' 而不是 'user_id' ,我不知道该添加什么而不是 'content_type_id' 使内容类型为只读。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Ridley Larsen    7 年前

    根据 docs for LogEntry ,字段名为 content_type 是的。 使用它应该可以在管理中获得一个只读内容类型字段。