1

In my admin.py I have

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

and

admin.site.register(LogEntry, LogEntryAdmin)

While I figured out adding 'user' rather than 'user_id', I can't figure out what to add instead of 'content_type_id' to make the content type read only.

4

1 回答 1

2

根据LogEntry 的文档,该字段刚刚命名content_type。使用它应该会在管理员中为您提供一个只读的内容类型字段。

于 2018-07-11T15:43:59.433 回答