When I create a form like this:

class IPTCForm(ModelForm):
  class Meta:
    model = IPTC
    fields = ['creator', 'datetime_value', 'headline', 'caption', 'instructions']

[...]

form = IPTCForm(instance=iptcObj)

The form already is populated with values from the object.

But when I use it in a formset instead, all the values are gone:

IPTCFormSet = formset_factory(IPTCForm)

Why is this happening?

有帮助吗?

解决方案

You need to pass in a query set:

IPTCFormSet = modelformset_factory(IPTCForm)
formset = IPTCFormSet(queryset=IPTC.objects.all())
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top