[Answer]-Display a model field while editing others model fields

1👍

According to the doc: a model form instance bound to a model object will contain a self.instance attribute that gives model form methods access to that specific model instance. Thus when you have a formset of Model such as BookFormSet

BookFormSet = modelformset_factory(Book, form=BookForm)
formset = BookFormSet(request.POST, queryset=Book.objects.order_by('-pk')[:10])

You could iterate it in template like:

<ul>{% for f in formset %}
    <li>{% if f.instance.pk %}title: {{ f.instance.title }}{% endif %} {{ f }}</li>
{% endfor %}</ul>
👤okm

Leave a comment