Django admin:仅在更改表单上排除字段 [英] Django admin: exclude field on change form only

查看:265
本文介绍了Django admin:仅在更改表单上排除字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有办法检测模型中的信息是否被添加或更改。

If there a way to detect if information in a model is being added or changed.

如果可以使用此信息来排除字段。

If there is can this information be used to exclude fields.

一些伪代码来说明我在说什么。

Some pseudocode to illustrate what I'm talking about.

class SubSectionAdmin(admin.ModelAdmin):
    if something.change_or_add = 'change':
        exclude = ('field',)
    ...

谢谢

推荐答案

class SubSectionAdmin(admin.ModelAdmin):
    # ...
    def change_view(self, request, object_id, extra_context=None):       
        self.exclude = ('field', )
        return super(SubSectionAdmin, self).change_view(request, object_id, extra_context)

这篇关于Django admin:仅在更改表单上排除字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆