【问题标题】:Multiple model forms with (foreign key) in multiple pages. Django多个页面中带有(外键)的多个模型表单。姜戈
【发布时间】:2015-05-24 16:22:35
【问题描述】:

这是我在 StackOverflow 上的第一个问题,请原谅我的错误。

现在,问题来了!

我目前正在 django 中制作网站,它有多个模型链接到一个父模型。现在我想创建一个多页表单来包含所有这些模型。怎么办???

这里有详细的问题:

models.py

class Profile(models.Model):

    user = models.OneToOneField(User)

    first_name = odels.CharField(
        max_length=255, validators=ONLY_LETTERS_VALIDATOR)
    last_name = odels.CharField(
        max_length=255, validators=ONLY_LETTERS_VALIDATOR)

    # And some other fields

class YMHTMobile(models.Model):

    profile = models.ForeignKey(Profile)

    mobile = models.CharField(max_length=10, validators=ONLY_DIGITS_VALIDATOR)

    is_active = models.BooleanField(default=True)

    def __unicode__(self):
        return '%s' % self.mobile

    class Meta:
        verbose_name_plural = 'Mobile Details'

# some more models with foreign key as profile

现在我想创建一个包含所有这些模型的多页表单(例如一个页面中的一个模型表单,然后单击下一步以获取另一个表单)

我该怎么做??

【问题讨论】:

    标签: python django forms django-models django-forms


    【解决方案1】:

    使用Form Wizard contrib 应用程序。

    更新:表单向导已从 django 1.8 移至单独的项目 - Django Form Tools

    【讨论】:

    猜你喜欢
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多