#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018cdab835b0-f51db4f7-3fc0-4a5d-a541-6519cb2e8e9c-000000%40eu-central-1.amazonses.com.

Reply via email to