【发布时间】:2018-01-06 17:59:24
【问题描述】:
我按照tutorial 将我的 Django 应用程序集成到我的 Django CMS 网站中。
我的应用 Sale 有两个模型,OrderModel() 和 CustomerModel(),它们都在 forms.py 中用于将某些字段传递给表单,如下所示:
class CustomerForm(forms.ModelForm):
class Meta:
model = CustomerModel
fields = ['firstname', 'surname', 'company', 'email',]
class OrderForm(forms.ModelForm):
class Meta:
model = OrderModel
fields = ['product', 'delivery_date',]
如教程中所述,在models.py 中我生成SalePluginModel 并在cms_plugins.py 中指定SalePluginPublisher 插件类,它负责为django CMS 提供渲染我的应用程序所需的信息,就像models.py:
class SalePluginModel(CMSPlugin):
title = models.CharField(u'title',
blank=True,
help_text=u'Optional. Title of the widget.',
max_length=64,
)
等等cms_plugins.py:
class SalePluginPublisher(CMSPluginBase):
model = SalePluginModel # model where plugin data are saved
module = _("Sale")
name = _("Sale Plugin") # name of the plugin in the interface
render_template = "sale/sale_plugin.html"
form = '' # How to pass multiple model forms here?
现在的问题是,只有一个表单类可以作为属性传递给CMSPluginBase。是否有可能在SalePluginPublisher 中包含两个表单类,或者一般来说,如何将我的应用程序与 Django CMS 中的两个模型和表单集成?
非常感谢您的帮助!
【问题讨论】:
标签: python django django-forms django-cms