On Tue, Mar 12, 2013 at 2:24 PM, Jim Kalafut <kala...@gmail.com> wrote: > Hi, > > I often want to use a ModelFormset by showing some editable fields, and then > showing some static data that is from the related model instance. For > example, I want to bulk edit a group of Person object phone numbers and > email address, but I'd also like to show (not edit) the person's name by > each form. Is there a straightforward way to get at that data, or configure > the ModelFormset in a way that I can accomplish this? My hack approaches so > far are ugly to the point that it is cleaner to just create a set of > form/model pairs myself and send them to the template. > > Thanks, > Jim >
Hi Jim In a ModelForm (also applies to the individual forms in a ModelFormSet), the instance that the form corresponds to will be aailable in the attribute 'instance'. Eg, in your template, you can do something like this: {% for form in formset %} {{ form.title }} {{ form.name }} <!-- read only below --> {{ form.instance.name }} {% endfor %} The docs only say that forms bound to a particular instance will have the attribute: https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#overriding-the-clean-method But from code inspection it seems that an empty instance would be created for any non bound model form - its the first thing BaseModelForm does when instantiated without a supplied instance. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.