在 Django 管理编辑对话框中创建/更新子对象
我想在管理编辑对话框中创建/更新“子对象”。
我有一个“CmsObject”模型,其中包含多个“CmsPageItem”对象(目前只有一个固定的 CmsPageItem,但将来会发生变化)。我希望在 change_form.html
页面中的某处显示一个附加文本区域字段,而不是让 StackedInline
小部件控制布局。
扩展 ModelAdmin 对话框的推荐方法是什么? 我希望我需要将表单字段推送到某处,或者在模板上下文中引入新值?
I'd like to create/update a "sub-object" within an admin edit dialog.
I have a "CmsObject" model, which contains several "CmsPageItem" objects (currently there will be just one fixed CmsPageItem, but that will change in the future). Rather then letting a StackedInline
widget control the layout, I would like to display one additional textarea field somewhere in the change_form.html
page.
What would the recommended approach to extend the ModelAdmin dialog be?
I expect I need to push a formfield somewhere, or introduce new values in the template context?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你看过 TabularInlines 吗?这里有一个例子: http://docs.djangoproject.com/en/dev/简介/tutorial02/
Have you looked at TabularInlines? There is an example here: http://docs.djangoproject.com/en/dev/intro/tutorial02/
我最终决定自己实现整个视图。对于大多数简单的对象,实现内联(使用或不使用自定义模板)就足够了。在这种情况下,我需要更多的控制,因此我完全覆盖了整个
add_view
和change_view
。FeinCMS 的编辑器窗口也执行此操作。
I've eventually settled to implement the whole view myself. For most simple objects, implementing the inlines (either with a custom template, or without) is good enough. In this situation I require more control, so I've overwritten the entire
add_view
andchange_view
completely.FeinCMS also does this for it's editor window.