﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35089	Allow admin filtering on GenericForeignKey and GenericRelation relations via search_fields	Chase Adams	nobody	"This ticket is to enable normal Admin search_fields syntax for GenericForeignKey and GenericRelation fields including additional query expression relation traversal using double underscore syntax.

For instance given these models:

{{{
class ModelA(Model):
    title = models.CharField(max_length=100)
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

class ModelB(Model):
    name = models.CharField(max_length=100)
    related_as = GenericRelation(ModelA)
}}}

Enable admin search in this format:

{{{
class ModelAAdmin(ModelAdmin):
    search_fields = ['content_object__name']
admin.site.register(ModelA, ModelAAdmin)

class ModelBAdmin(admin.ModelAdmin):
    search_fields = ['related_as__title']
admin.site.register(ModelB, ModelAAdmin)
}}}

Additionally, further double underscore relation traversal should be implemented:

{{{
    search_fields = ['content_object__foreignkey_field__name']
}}}

{{{
    search_fields = ['related_as__other_content_object__name']
}}}"	New feature	closed	contrib.admin	5.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
