Django模型继承。隐藏或删除字段 [英] Django Model Inheritance. Hiding or removing fields
问题描述
另外 - 如果一个不需要的字段是需要?我的第一个想法是覆盖保存方法,只是放入一个默认值。
如果你继承了模型,那么它尝试隐藏或禁用任何现有的字段可能不明智。你可能做的最好的事情就是你建议的:覆盖 save()
并处理你的逻辑。
I want to inherit a model class from some 3rd party code. I won't be using some of the fields but want my client to be able to edit the model in Admin. Is the best bet to hide them from Admin or can I actually prevent them being created in the first place?
Additionally - what can I do if one of the unwanted fields is required? My first thought is to override the save method and just put in a default value.
If you are inheriting the model then it is probably not wise to attempt to hide or disable any existing fields. The best thing you could probably do is exactly what you suggested: override save()
and handle your logic in there.
这篇关于Django模型继承。隐藏或删除字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!