我正在重用来自 cmsplugin_news 的 News 模型,只是在我的继承模型中添加了一些额外的字段。(多表继承,就像这里解释的那样。
from cmsplugin_news.models import News
class News(News):
departments = models.ManyToManyField('department.Department', blank=True, related_name="news")
在我的 admin.py 上,我正在扩展 NewsAdmin 以设置我自己的表单:
class MyNewsAdmin(NewsAdmin):
form = NewsModelForm
我在forms.py中定义的:
from news.models import News
class NewsModelForm(NewsForm):
class Meta:
model = News
widgets = {
'excerpt': CKEditorWidget(config_name='basic'),
'content': CKEditorWidget(config_name='default')
}
def _get_widget(self):
from ckeditor.widgets import CKEditorWidget
return CKEditorWidget()
当我从 shell 控制台保存对象时,模型继承似乎运行良好。但是当我尝试从 django 管理员创建一个 MyNews 对象并将其链接到一个部门时,该字段不会被保存。或者至少这种变化没有在任何地方显示
unicms-testnews=> select * from cmsplugin_news_news;
id | title | slug | excerpt | content | is_published | pub_date | created | updated | link
----+-------+------+---------+---------+--------------+------------------------+-------------------------------+-------------------------------+------
1 | dfad | dfad | | | f | 2013-09-10 13:44:46+02 | 2013-09-10 13:45:04.709556+02 | 2013-09-10 13:57:05.568696+02 |
(1 row)
unicms-testnews=> select * from news_news;
news_ptr_id
-------------
1
(1 row)
unicms-testnews=> select * from news_news_departments;
id | news_id | department_id
----+---------+---------------
1 | 1 | 1
(1 row)
我什么都看不懂,谁能帮帮我?非常感谢!