【发布时间】:2012-07-15 19:29:25
【问题描述】:
所以,我仍然是 Django 的菜鸟,我想知道如何执行以下操作:
所以可以说我有类似下面的代码:
class UserProfile(models.Model):
#Some fields
class UserProfileOther(models.Model):
#Some other fields that I want in another table for organization
user_profile = models.OneToOneField(UserProfile)
我现在如何创建包含上述两种模型的表单?
【问题讨论】:
-
根据我的经验,您将创建第 3 个 FormClass,即表单(不是模型!),然后使用它的 save 正确写回数据。它让您在显示表单时更加灵活。
-
您是否有理由希望两个模型具有相同的形式?您只是想制作一个 HTML 表单(因此用户只需提交一次)?
标签: django django-models django-forms