Search code examples
djangodjango-formsinline-formset

Accessing Parent of Inline Form Sets in template?


I am wondering how to access the parent of the inline form set in Django. Here is what I am currently doing:

views.py

def upload(request):
    [Code Ommitted]
    formSet = inlineformset_factory(Tombstone, Tank, form = TombstoneForm)
        form = formSet(instance=t)
        return render(request, 'edit_form2.html', {'form': form})

In this instance I want to access the Tombstone object in my template.

Edit: I want to access the form element associated with each field in the Tombstone object.


Solution

  • You can use formset's instance attribute:

    {{ form.instance.id }}