Opened 6 years ago

Closed 6 years ago

#26279 closed Bug (duplicate)

Admin search_fields doesn't support nested lookup from JSONField

Reported by: Nicolas Delaby Owned by: nobody
Component: contrib.admin Version: 1.9
Severity: Normal Keywords: admin
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Model

class Foo(models.Model):
    json = JSONField()

Admin

@admin.register(Foo) 
class FooAdmin(admin.ModelAdmin):
    search_fields = ('json__key',)

request from the browser (enter anything in search box).

GET /admin/project/foo/?q=123

I get this error

File "/home/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/views/main.py", line 356, in get_queryset
    request, qs, self.query)
  File "/home/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 903, in get_search_results
    if lookup_needs_distinct(self.opts, search_spec):
  File "/home/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/utils.py", line 32, in lookup_needs_distinct
    import pdb; pdb.set_trace()
  File "/home/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/options.py", line 582, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: Foo has no field named 'key'

I'll be glad to have some guidance where is the best place to write the test.
Then I can work on making a fix.

Change History (3)

comment:1 Changed 6 years ago by Nicolas Delaby

Summary: Admin search_fields doesn't support nested loopkup from JSOFieldAdmin search_fields doesn't support nested lookup from JSOField

comment:2 Changed 6 years ago by Nicolas Delaby

Summary: Admin search_fields doesn't support nested lookup from JSOFieldAdmin search_fields doesn't support nested lookup from JSONField

comment:3 Changed 6 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Duplicate of #26184

Note: See TracTickets for help on using tickets.
Back to Top