在 Django 管理编辑对话框中创建/更新子对象

发布于 2024-09-30 08:43:53 字数 280 浏览 0 评论 0原文

我想在管理编辑对话框中创建/更新“子对象”。

我有一个“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哽咽笑 2024-10-07 08:43:53

你看过 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/

行至春深 2024-10-07 08:43:53

我最终决定自己实现整个视图。对于大多数简单的对象,实现内联(使用或不使用自定义模板)就足够了。在这种情况下,我需要更多的控制,因此我完全覆盖了整个 add_viewchange_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 and change_view completely.

FeinCMS also does this for it's editor window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文