Applying filter_horizontal to an inlinemodeladmin instance?

14 views
Skip to first unread message

Bass'd God

unread,
Aug 7, 2017, 3:52:15 PM8/7/17
to Django users
According to Django documentation it's possible. filter_horizontal is supposed to extend to InlineModelAdmin. But I've been at a pretty bad stopping point of not knowing the syntax for how to get this to work, and not being able to even find an example of someone doing this.

I have a model called Statement. Statement has an m2m relationships with another model called Keywords. In other words, each statement has a set of keywords. and I'm trying to change its change/add page by allowing one to be able to modify the keywords associated with a Statement.

However, when I design admin.py like this and run python manage.py makemigrations, I get the error at the bottom. statements is a m2m field within Keywords, so I'm not really sure what to do at this point. I've been trying a lot of variants but nothing's really working and I don't understand where to begin.


class KeywordInline(admin.TabularInline):
    model = Keyword.statement.through
    filter_horizontal = ('statement',)

class KeywordAdmin(admin.ModelAdmin):
    inlines = [KeywordInline,]

class StatementAdmin(admin.ModelAdmin):
    inlines = [ KeywordInline,]

SystemCheckError: System check identified some issues:

ERRORS:
<class 'gtr_site.admin.KeywordInline'>: (admin.E020) The value of 'filter_horizontal[0]' must be a many-to-many field.

Reply all
Reply to author
Forward
0 new messages