Opened 10 years ago

Closed 10 years ago

#23351 closed Cleanup/optimization (duplicate)

Admin Search Field error for related lookup

Reported by: Ezequiel Bertti Owned by: nobody
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords:
Cc: florent.pastor@…, zeraien Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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')


Change History (4)

comment:1 by Ramiro Morales, 10 years ago

Resolution: worksforme
Status: newclosed

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.

comment:2 by Florent Pastor, 10 years ago

Cc: florent.pastor@… added

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.

in reply to:  1 comment:3 by zeraien, 10 years ago

Cc: zeraien added
Resolution: worksforme
Severity: Release blockerNormal
Status: closednew
Type: UncategorizedBug
Version: 1.7-rc-21.7

Replying to 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

Version 0, edited 10 years ago by zeraien (next)

comment:4 by Simon Charette, 10 years ago

Resolution: duplicate
Status: newclosed
Type: BugCleanup/optimization

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.

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