m2m admin relationship selector with filter_horizontal and large datasets

50 views
Skip to first unread message

James Y

unread,
Dec 10, 2014, 7:32:20 AM12/10/14
to django...@googlegroups.com
I have a Category model that is m2m with an Article model and need to make categories selectable in my article admin. So I'm using a filter_horizontal and the problem is that I have thousands of categories and do not want to load them all into the left hand side (lhs) of filter_horizontal.

Is there a way to limit the lhs to just a search functionality instead of a category browse?

Is there another widget I should use just for searching categories to make m2m relationships?

Thanks

Collin Anderson

unread,
Dec 11, 2014, 3:25:51 PM12/11/14
to django...@googlegroups.com
Hi,

Check out raw_id_fields if you haven't.

Either on ArticleAdmin:
raw_id_fields = ['categories']

Or as an inline:
class CategoryInline(models.TabularInline):
    model
= Article.categories.through
    extra
= 0
    raw_id_fields
= ['category']

Collin

James Y

unread,
Dec 11, 2014, 8:03:52 PM12/11/14
to django...@googlegroups.com
Thanks Collin, I looked at raw field ids, but feels too basic.  I'm attempting to implement autocomplete_light which seems to offer m2m selection.  

IT would seem that this would be a common problem: select from a large list without displaying that entire list.  
filter_horizontal would work if I could turn off the left hand side list and still get the search and select functions. I wish I had time to extend that.
Reply all
Reply to author
Forward
0 new messages