离开 PHP 之前的三个问题:表单集、数据源和远程身份验证
我已经使用 CakePHP 很长时间了,并且对用它开发网站感到很舒服。然而,我确实更喜欢 Python,而不是 PHP,并且想迁移到 Django。
编辑:分成三个单独的问题
如何以一种形式混合多个模型?我知道表单集用于此目的,但我找不到关于此的像样的教程(视图+模板)。在 Cake 中,我可以在我的视图(模板)中简单地实现这一点:
echo $this->Form->input('User.title');
echo $this->Form->input('Profile.website');
echo $this->Form->input('Comment.0.title');
echo $this->Form->input('Comment.1.title');
这将混合用户模型、配置文件模型并在一种形式中添加两个注释。如何用 Django 做到这一点?
谢谢!
I've been using CakePHP for a long time now and feel comfortable developing sites with it. I do however like Python more then PHP and would like to move to Django.
EDIT: split in three separate questions
How can I mix multiple models in one form? I know formsets are used for this, but I can't find a decent tutorial on this (views + template). In Cake I can simply to this in my view (template):
echo $this->Form->input('User.title');
echo $this->Form->input('Profile.website');
echo $this->Form->input('Comment.0.title');
echo $this->Form->input('Comment.1.title');
This would mix a User model, a Profile model and add two comments in one form. How to do this with Django?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第 1 部分,这比您想象的要容易得多:
forms.py:
views.py:
template.html:
In regards to part 1, this is much easier than you may think:
forms.py:
views.py:
template.html: