[Answered ]-How to use checkboxes in Django Admin for a ManyToMany field through a model

2👍

According to the Django docs, when you use a through argument to a ManyToManyField, the admin will not display a widget by default.

So, in this case you must use inlines, unfortunately.

However, if you don’t use a through argument, you can simply have a ModelAdmin like this:

class CarAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.ManyToManyField: {'widget': CheckboxSelectMultiple},
    }

This way you have the checkboxes, but you lose the trophies reference.

I know, it isn’t a fair world. I thought it would exist another way, but the Django docs is clear about why you have to use inlines with the through argument.

Leave a comment