[Django] #23351: Admin Search Field error for related lookup

159 views
Skip to first unread message

Django

unread,
Aug 22, 2014, 11:06:32 PM8/22/14
to django-...@googlegroups.com
#23351: Admin Search Field error for related lookup
----------------------------------------------+----------------------
Reporter: ebertti | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.7-rc-2
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+----------------------
I'm using Django Version 1.7c2 and I have these two models :
{{{
class Module(models.Model):
name = models.CharField(max_length=255)

class Subject(models.Model):
module = models.ForeignKey(Module)
}}}
And this Admin Class:
{{{
class SubjectAdmin(admin.ModelAdmin):
search_fields = ('module__name',)
}}}
And i'm getting this error

FieldError at /admin/app/subject/
Relation fields do not support nested lookups

on django\db\models\fields\related.py in get_lookup_constraint
raise exceptions.FieldError('Relation fields do not support nested
lookups')

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

Django

unread,
Aug 23, 2014, 7:36:24 AM8/23/14
to django-...@googlegroups.com
#23351: Admin Search Field error for related lookup
-------------------------------------+-------------------------------------
Reporter: ebertti | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 1.7-rc-2
(models, ORM) | Resolution:
Severity: Release blocker | worksforme
Keywords: | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ramiro):

* status: new => closed
* needs_docs: => 0
* resolution: => worksforme
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

I can't reproduce this with the information provided and using a simple
setup containing only the code shown by the OP.

Reopne if you can post more details.

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

Django

unread,
Oct 24, 2014, 7:31:57 AM10/24/14
to django-...@googlegroups.com
#23351: Admin Search Field error for related lookup
-------------------------------------+-------------------------------------
Reporter: ebertti | Owner: nobody

Type: Uncategorized | Status: closed
Component: Database layer | Version: 1.7-rc-2
(models, ORM) | Resolution:
Severity: Release blocker | worksforme
Keywords: | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by pfif):

* cc: florent.pastor@… (added)


Comment:

I have a similar issue, except that my model is slightly more complex. The
{{{Module}}} class inherit from another one, and I use a
{{{ManyToManyField}}}, instead of a {{{ForeignKey}}}.

{{{
class Base(models.Model):
name = models.CharField(max_length=100)

class Module(Base):
pass

class Subject(models.Model):
module = models.ManyToManyField(Module)
}}}

The admin class is still the same :


{{{
class SubjectAdmin(admin.ModelAdmin):
search_fields = ('module__name',)
}}}

When I try to search, I get this issue :

{{{
Django Version: 1.6.5
Exception Type: TypeError
Exception Value:
Related Field got invalid lookup: icontains
Exception Location: /usr/local/lib/python2.7/dist-
packages/django/db/models/fields/related.py in get_lookup_constraint, line
1123
Python Executable: /usr/bin/python
Python Version: 2.7.6
}}}

By the way, I run Django 1.6.5, I did not test my project under django
1.7.

--
Ticket URL: <https://code.djangoproject.com/ticket/23351#comment:2>

Django

unread,
Feb 11, 2015, 11:13:45 AM2/11/15
to django-...@googlegroups.com
#23351: Admin Search Field error for related lookup
-------------------------------------+-------------------------------------
Reporter: ebertti | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
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 zeraien):

* status: closed => new
* severity: Release blocker => Normal
* cc: zeraien (added)
* type: Uncategorized => Bug
* version: 1.7-rc-2 => 1.7
* resolution: worksforme =>


Comment:

Replying to [comment:1 ramiro]:


> I can't reproduce this with the information provided and using a simple
setup containing only the code shown by the OP.
>
> Reopne if you can post more details.


I discovered the problem seems to be related to this ticket:
https://code.djangoproject.com/ticket/23697

If using this: `search_fields = ('module__name',)` but `name` does not
exist in the `module` model, this error is thrown.

Using django 1.7.3

Full trace: https://gist.github.com/anonymous/f9abcb78c77466c35dcb

--
Ticket URL: <https://code.djangoproject.com/ticket/23351#comment:3>

Django

unread,
Feb 12, 2015, 1:06:46 AM2/12/15
to django-...@googlegroups.com
#23351: Admin Search Field error for related lookup
-------------------------------------+-------------------------------------
Reporter: ebertti | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution: duplicate
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 charettes):

* status: new => closed

* type: Bug => Cleanup/optimization
* resolution: => duplicate


Comment:

Thanks for the report but let's keep this ticket closed by marking it as a
duplicate instead and move all discussion to #23697.

The fix suggested by Tim on #23697 should prevent reports similar to this
one which were probably caused by a simple typo in the field name.

--
Ticket URL: <https://code.djangoproject.com/ticket/23351#comment:4>

Reply all
Reply to author
Forward
0 new messages