Django模型继承。隐藏或删除字段 [英] Django Model Inheritance. Hiding or removing fields

查看:153
本文介绍了Django模型继承。隐藏或删除字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一些第三方代码继承一个模型类。我不会使用某些字段,但希望我的客户端能够在Admin中编辑模型。最好的办法是把它们从管理员中隐藏起来,或者我实际上可以防止它们被创建在第一位?



另外 - 如果一个不需要的字段是需要?我的第一个想法是覆盖保存方法,只是放入一个默认值。

解决方案

如果你继承了模型,那么它尝试隐藏或禁用任何现有的字段可能不明智。你可能做的最好的事情就是你建议的:覆盖 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屋!

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