How to show filter_horizontal on reverse side of ManyToManyField?

Hi folks – I have essentially the following model, plus the default Group model, so a study can be accessed by many groups and each group can give access to many studies:

# models.py
from django.contrib.auth.models import Group
from django.db import models

class Study(models.Model):
    groups = models.ManyToManyField(Group, blank=True)

Together with a small amount of configuration, this shows the fancy filter_horizontal widget on the admin page for each study:

# admin.py
from django.contrib import admin
from .models import Study

@admin.register(Study)
class StudyAdmin(admin.ModelAdmin):
    filter_horizontal = ["groups"]

I’d like to show the same widget on the admin page for each group, but I can’t figure out how to do that. I can’t find a value to put in GroupAdmin.filter_horizontal that won’t result in an error like “The value of ‘filter_horizontal[0]’ must be a many-to-many field.” or “The value of ‘filter_horizontal[0]’ refers to ‘study_set’, which is not a field of ‘auth.Group’.”, and trying to use the officially-documented approach with inlines by doing something like this:

class StudyGroupInline(admin.TabularInline):
    model = Study.groups.through

admin.site.unregister(Group)
@admin.register(Group)
class GroupAdmin(BaseGroupAdmin):
    inlines = [StudyGroupInline]

results in this bizarre-looking widget instead:

I can specify StudyGroupInline.extra = 1 to get rid of some of the additional rows, but it’s still a far cry from the nice-looking two-column widget you get by default. What am I missing?

I’m using Django 5.1.3 and Python 3.12.7.

I guess I will bump this once, since it got no reply as yet.

The answer you may be looking for can be found here: Overriding admin many to many form fields

Edit: While its not an exact solution, it should help you in obtaining the solution to your problem. I tried it with my custom models since you did not provide yours and it seems to work.

I have 3 models, A, B, AB_Map. Models A and B need their own many to many relationship field that references AB_Map as the through table. Once you have provided a through argument though django does not inherently support filter_horizontal so if you wish to obtain the same result, you should still supply each field as a filter_horizontal then use the answer found in the stack overflow post to override the form field.