[Django] #35089: Allow admin filtering on GenericForeignKey and GenericRelation relations via search_fields

10 views
Skip to first unread message

Django

unread,
Jan 5, 2024, 12:42:39 PM1/5/24
to django-...@googlegroups.com
#35089: Allow admin filtering on GenericForeignKey and GenericRelation relations
via search_fields
-------------------------------------------+------------------------
Reporter: bringfido-adams | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
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']
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/35089>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 5, 2024, 1:06:41 PM1/5/24
to django-...@googlegroups.com
#35089: Allow admin filtering on GenericForeignKey and GenericRelation relations
via search_fields
-------------------------------+--------------------------------------
Reporter: Chase Adams | Owner: nobody
Type: New feature | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Chase Adams):

* status: new => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/35089#comment:1>

Reply all
Reply to author
Forward
0 new messages