Opened 11 years ago
Closed 11 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)
follow-up: 3 comment:1 by , 11 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
comment:2 by , 11 years ago
| Cc: | 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.
comment:3 by , 11 years ago
| Cc: | added |
|---|---|
| Resolution: | worksforme |
| Severity: | Release blocker → Normal |
| Status: | closed → new |
| Type: | Uncategorized → Bug |
| Version: | 1.7-rc-2 → 1.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
comment:4 by , 11 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
| Type: | Bug → Cleanup/optimization |
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.