【问题标题】:get initial value of ModelChoiceField in inlineformset获取 inlineformset 中 ModelChoiceField 的初始值
【发布时间】:2013-08-03 16:10:19
【问题描述】:

我在 models.py 中有一个模型

class Page(models.Model):
    url = models.CharField(verbose_name="url", unique=True, db_index=True, max_length=255)
    template = models.ForeignKey(Template)


class PageToBlock(models.Model):
    page = models.ForeignKey(Page)
    placeholder = models.ForeignKey(Placeholder)
    block = models.ForeignKey(Block,null=True)

以及视图中的一些代码

PTBFormSet = inlineformset_factory(models.Page, models.PageToBlock, extra=0, can_delete=False)
formset = PTBFormSet(instance=page)
for form in formset:
    # i need initial here for processing
    print form.fields['placeholder'].initial #print None!, but in final rendered form it has value

如何提取首字母?

【问题讨论】:

  • 试试form.initials['placeholder']

标签: python django inline-formset


【解决方案1】:

form.initials['placeholder'] 工作正常

【讨论】:

    猜你喜欢
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    相关资源
    最近更新 更多