I have the following model:
class Hospital(models.Model):
name = models.CharField(max_length=200)
authorized_users = models.ManyToManyField(User)
Displaying a filter_horizontal widget on the Hospital admin page to manage the ManyToManyField is pretty simple:
class HospitalAdmin(admin.ModelAdmin):
filter_horizontal = ('authorized_users', )
admin.site.register(models.Hospital, HospitalAdmin)
However, what I'd REALLY like is to display that widget AS WELL on the "Change User" admin page, inline with the rest of the User's information. It stands to reason that ManyToManyFields SHOULD be modifiable from both directions - to authorize multiple users for a single hospital, the above de-facto situation is fine. However, to authorize one user on multiple hospitals, the current situation would require visiting the admin page for each hospital and selecting the one user in question - absurd.
I will add that I AM using the UserProfile methodology to store additional info about users (what type of user they are, etc). One POSSIBLE solution would be to make the Hospital's ManyToManyField reference UserProfile instead of User. Then I could add a ManyToManyField(Hospital, through=Hospital.authorized_users.through) to UserProfile, thus allowing me to add the filter_horizontal widgets to both ends. However, this is non-ideal since it'd be a pain later to reference the connection. Imagine I want to get the first user authorized for a given hospital. Rather than hosp_name.authorized_users.all()[0], I'd have to do something like hosp_name.authorized_users.all()[0].user. I'm not even sure how I'd accomplish the equivalent of hosp_name.authorized_users.all() to get the full list (as that would return a list of UserProfiles, not Users.