I have models A, B, and AB.
A objects have a ManyToManyField called A.m that can link to many B objects, through my intermediary model AB.
I have a very nice TabularInline section full of AB objects, on my admin page for my A model.
All is well. Except that the TabularInline section shows "Add" and "Change" buttons for the B object in each AB object's row, and I want to remove those buttons. I still want to be able to add, change, and delete AB objects rows, just not the B objects they reference.
I have tried setting the can_add_related, can_change_related, can_delete_related attributes to False, but this does nothing.
class ABInline(admin.TabularInline):
model = AB
def get_form(self, request, obj=None, **kwargs):
form = super(ABInline, self).get_form(request, obj, **kwargs)
form.base_fields['m'].widget.can_add_related = False
form.base_fields['m'].widget.can_change_related = False
form.base_fields['m'].widget.can_delete_related = False
return form
Is this a bug? Or is there a different way to accomplish this for TabularInline fields?