def match(self, request):

        context = dict(self.admin_site.each_context(request))
        context.update({'title': 'Match authority records'})
        if request.method == 'POST':
            chosen = match(request, DraftAuthority, Authority)

            # The user may not have chosen any production authority records, in
            #  which case we simply return to the changelist.
            if len(chosen) > 0:
                authority_type = ContentType.objects.get_for_model(Authority)

                AuthorityInlineFormset = formset_factory(AuthorityForm, extra=0)
                AttributeInlineFormSet = formset_factory(AttributeForm, extra=1)
                LinkedDataInlineFormSet = formset_factory(LinkedDataForm, extra=1)

                # Generate initial data for formsets.
                initial_attribute = []
                initial_linkeddata = []
                initial_attribute_groups = []    # Associates forms in formset
                initial_linkeddata_groups = []   #  with choices.
                a, l = 0, 0
                for draftauthority, authority in chosen:
                    attribute_group = []
                    linkeddata_group = []
                    for attribute in authority.attributes.all():
                        attribute_group.append(a)
                        initial_attribute.append({
                            'id': attribute.id,
                            'value': attribute.value.get_child_class().value,
                            'type_controlled': attribute.type_controlled,
                            'value_freeform': attribute.value_freeform,
                            'source_content_type': authority_type.id,
                            'source_instance_id': authority.id,
                        })
                        a += 1

                    for linkeddata in authority.linkeddata_entries.all():

                        linkeddata_group.append(l)
                        initial_linkeddata.append({
                            'id': linkeddata.id,
                            'universal_resource_name': linkeddata.universal_resource_name,
                            'type_controlled': linkeddata.type_controlled,
                            'subject_content_type': authority_type.id,
                            'subject_instance_id': authority.id,
                        })
                        l += 1
                    initial_attribute_groups.append(attribute_group)
                    initial_linkeddata_groups.append(linkeddata_group)

                # Generate formsets using the initial data generated above.
                attribute_formset = AttributeInlineFormSet(prefix='attribute', initial=initial_attribute)
                linkeddata_formset = LinkedDataInlineFormSet(prefix='linkeddata', initial=initial_linkeddata)

                # Sort the formsets out into groups based on the Authority to
                #  which they correspond.
                attribute_forms = [[attribute_formset[i] for i in group] for group in initial_attribute_groups]
                linkeddata_forms = [[linkeddata_formset[i] for i in group] for group in initial_linkeddata_groups]

                # Formset for the Authority records themselves.
                formset = AuthorityInlineFormset(prefix='authority', initial=[{
                        'id': authority.id,
                        'name': authority.name,
                        'type_controlled': authority.type_controlled,
                        'description': authority.description,
                        'record_status': authority.record_status,
                        'record_history': authority.record_history,
                        'administrator_notes': authority.administrator_notes,
                        'public': authority.public,
                    } for draftauthority, authority in chosen])

                # Here we stitch together the formsets so that each
                #  DraftAuthority is grouped together whith its corresponding
                #  Authority (into which it will be merged), the Authority's
                #  pre-filled form, and the Authority's share of the
                #  LinkedData and Attribute formsets. This way we can separate
                #  all of these bits out according to DraftAuthority/Authority
                #  pairs in the template.
                chosen = zip(zip(*chosen)[0], zip(*chosen)[1], formset, attribute_forms, linkeddata_forms)

                context.update({
                    'chosen_suggestions': chosen,
                    'authority_formset': formset,
                    'linkeddata_formset': linkeddata_formset,
                    'attribute_formset': attribute_formset,
                    'attribute_template_form': attribute_formset[-1],
                    'linkeddata_template_form': linkeddata_formset[-1],
                })
                # But if they did choose production authority records, we want
                #  to confirm that they wish to proceed with the merge action.
                return TemplateResponse(request, "admin/authority_match_do.html", context)

        # Non-POST requests should take the user back to the changelist.
        return HttpResponseRedirect(reverse('admin:zotero_draftauthority_changelist'))
The match_citations admin action will route POST data here. If the user
dataset/ETHPy150Open upconsulting/IsisCB/isiscb/zotero/admin.py/DraftAuthorityAdmin.match