How to omit object name from Django's TabularInline admin view?

后端 未结 6 1862
南方客
南方客 2021-02-01 14:33

I\'m using Django\'s TabularInline admin view to edit category objects related to a main topic object, as shown here:

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 15:20

    I thought I'd chime in that editing your template is going to be the easiest.

    I tried iterating over the formsets in render_change_form but unfortunately, the major problem is that InlineAdminForms are constructed dynamically upon iteration in the template so you can't just set inlineadminform.original = None or modify the context.

    They don't even exist until assigned a variable in the template.

    # InlineAdminFormset
    def __iter__(self):
        for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()):
            yield InlineAdminForm(self.formset, form, self.fieldsets,
                self.opts.prepopulated_fields, original, self.readonly_fields,
                model_admin=self.model_admin)
    

    and the only easily non-hackishly accessible hook we have there is overriding InlineAdminFormset.formset.get_queryset() which breaks other things.

    Can I share some code nobody should ever really look at but works and makes me crack up laughing? I owe you one payne. Hope I can get to sleep tonight.

提交回复
热议问题