pythondjangodjango-formsdjango-adminformset

Django, extract value from formset


I have overridden save_formset method to extract data from admin page. Here is how my code looks like:

def save_formset(self, request, form, formset, change):
    for f in formset:
        print('Voter address is: ', f['voter_address'])
    super().save_formset(request,form, formset, change)

I get output as:

enter image description here

But I want to extract actual value which is "klncklas," and for second one I would like to know that there is no value present. How I can achieve this?


Solution

  • def save_formset(self, request, form, formset, change):
        # Create instances. Each instance will be a "row" (obj) of the inline model
        instances = formset.save(commit=False)
        # Iterate over the instances (objects of the Inline Model)
        for instance in instances:
            # Get the object's attribute (Model field)
            print(instance.voter_address)
        super().save_formset(request,form, formset, change)