我已经成功地安装了django cmsplugin_contact,但我真正需要的是将表单保存到数据库中。我一直在阅读关于newForms的文章,但是它所暗示的python文件结构有很大的不同,所以我似乎不能让它工作。
关于如何轻松地将其保存到数据库中,有什么线索吗?
我尝试了几种不同的方法,但没有得到好的结果。
任何帮助都是非常感谢的。谢谢。
发布于 2012-06-13 13:58:05
顺便说一句,contact插件非常棒,忘了文档吧,只需阅读代码,它非常简单。
这个帖子很老了,但我喜欢这个问题,我想我也需要这样一个东西,所以这是一个答案:
你可以创建一个新的联系人应用程序,smartcontact,它扩展了默认的联系人插件...
联系人插件使用以下形式:
class ContactForm(forms.Form):
email = forms.EmailField()
subject = forms.CharField(required=False)
content = forms.CharField(widget=forms.Textarea())然后,您需要做的就是在该应用程序文件夹中创建一个cms_plugins.py文件,并扩展contacts应用程序以继承该行为并修复您想要更改的内容。所以看看这段未经测试的代码:
from cmsplugin_contact.cms_plugins import ContactPlugin
from smartcontact.models import SmartContact #<-- your SmartContact model.
class SmartContactPlugin(ContactPlugin):
def send(self, form, site_email):
sc = SmartContact()
sc.from_email = form.cleaned_data['email']
sc.subject = form.cleaned_data['subject']
sc.content = form.cleaned_data['content']
#and then if you want to also send email, uncomment this to also call
#parent's version.
#ContactPlugin.send(self, form, site_email)所以我猜你需要一个模型来保存它,从上面需要的字段很容易做到这一点。
不要忘记将你的新应用程序添加到settings.py中,并将plugin_pool.register_plugin(SmartContactPlugin)粘贴到新的cms_plugins.py文件的末尾。
发布于 2011-12-20 03:51:40
如果这个插件没有任何文档,你也可以跳过这个插件,只使用你自己的视图代码,这些代码是通过分配给你的页面的CMS应用程序挂接的。
https://stackoverflow.com/questions/8564709
复制相似问题