Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  40] [ 2]  / answers: 1 / hits: 40641  / 14 Years ago, tue, march 22, 2011, 12:00:00

I find the the Django Admin's default models.ManyToManyField widget to be cumbersome to use. It's the HTML select element and if you have a lot of Objects of the other model then it's quite impractical to actually find the other Objects you want to associate with this Object. And if you have a lot of objects of the other model it seems to even slows down the rendering of the Admin page.



I'm aware that I can build my own custom admin widget and apply it to my ManyToManyFields as I see fit, but are there any pre-built ones out there that I might use instead? In my dreams, I picture an auto-completing text input HTML widget. Is this even practical/possible to do in the Django admin framework?



Thanks.


More From » django

 Answers
233

Try using the filter_horizontal attribute on your admin class, for example:



class SomeModelAdmin(admin.ModelAdmin):
filter_horizontal = ('users',)


As mentioned in the documentation, adding a ManyToManyField to this list will instead use a nifty unobtrusive JavaScript filter interface that allows searching within the options. filter_vertical does the same thing with a slightly different layout.


[#93149] Sunday, March 20, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
demondp

Total Points: 154
Total Questions: 97
Total Answers: 99

Location: Mali
Member since Thu, Jul 9, 2020
4 Years ago
;