TypeError: Related Field has invalid lookup: icontains

2,087 views
Skip to first unread message

Alessandro Ronchi

unread,
Jan 21, 2009, 10:21:01 AM1/21/09
to django...@googlegroups.com
When one tries to make a search in admin with a model table he gets this error:

TypeError: Related Field has invalid lookup: icontains

is there anyway to solve it and make it returns nothings instead of 500 error?

--
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

Karen Tracey

unread,
Jan 21, 2009, 11:15:34 AM1/21/09
to django...@googlegroups.com
On Wed, Jan 21, 2009 at 10:21 AM, Alessandro Ronchi <alessand...@soasi.com> wrote:

When one tries to make a search in admin with a model table he gets this error:

TypeError: Related Field has invalid lookup: icontains

is there anyway to solve it and make it returns nothings instead of 500 error?

Some details of the model and admin defs in use here would help someone help you.

Karen

Alessandro Ronchi

unread,
Jan 21, 2009, 3:04:00 PM1/21/09
to django...@googlegroups.com
2009/1/21 Karen Tracey <kmtr...@gmail.com>:

A part of my models.py:
http://dpaste.com/111580/

and my admin:
http://dpaste.com/111581/

Thanks in advance!

Karen Tracey

unread,
Jan 21, 2009, 5:07:52 PM1/21/09
to django...@googlegroups.com
On Wed, Jan 21, 2009 at 3:04 PM, Alessandro Ronchi <alessand...@soasi.com> wrote:

2009/1/21 Karen Tracey <kmtr...@gmail.com>:
> On Wed, Jan 21, 2009 at 10:21 AM, Alessandro Ronchi
> <alessand...@soasi.com> wrote:
>>
>> When one tries to make a search in admin with a model table he gets this
>> error:
>>
>> TypeError: Related Field has invalid lookup: icontains
>>
>> is there anyway to solve it and make it returns nothings instead of 500
>> error?
>
> Some details of the model and admin defs in use here would help someone help
> you.
>
> Karen

A part of my models.py:
http://dpaste.com/111580/

and my admin:
http://dpaste.com/111581/

Thanks in advance!

Egads, they're huge.  Any way you could cut that down to a small failing example?  Or at least mention which model you are trying the search on?  Also a traceback instead of just the last error message would probably help, as it might give some clue where to start looking.

Karen

Alessandro Ronchi

unread,
Jan 22, 2009, 3:01:28 AM1/22/09
to django...@googlegroups.com
2009/1/21 Karen Tracey <kmtr...@gmail.com>:

> Egads, they're huge. Any way you could cut that down to a small failing
> example? Or at least mention which model you are trying the search on?
> Also a traceback instead of just the last error message would probably help,
> as it might give some clue where to start looking.

It falls on SchedaBilancioGenere model. I cannot replicate on a smaller model.

They're huge, but all the fields are not important: it seems if falls
on a related field.

This is the trackback:
http://dpaste.com/111757/

Karen Tracey

unread,
Jan 22, 2009, 10:40:41 AM1/22/09
to django...@googlegroups.com
On Thu, Jan 22, 2009 at 3:01 AM, Alessandro Ronchi <alessand...@soasi.com> wrote:

2009/1/21 Karen Tracey <kmtr...@gmail.com>:

> Egads, they're huge.  Any way you could cut that down to a small failing
> example?  Or at least mention which model you are trying the search on?
> Also a traceback instead of just the last error message would probably help,
> as it might give some clue where to start looking.

It falls on SchedaBilancioGenere model. I cannot replicate on a smaller model.

They're huge, but all the fields are not important: it seems if falls
on a related field.

This is the trackback:
http://dpaste.com/111757/


Ah, you have in your search_fields for SchedaBilancioGenereOptions 'impresa', which is a ForeignKey.  You need to specify what field within the related model you want to search, so 'impresa__fieldname'.  (If there are multiple fields you need to list each explicitly, using the standard double-underscore syntax.) 

Karen

Alessandro Ronchi

unread,
Jan 22, 2009, 5:02:34 PM1/22/09
to django...@googlegroups.com
2009/1/22 Karen Tracey <kmtr...@gmail.com>:

> Ah, you have in your search_fields for SchedaBilancioGenereOptions
> 'impresa', which is a ForeignKey. You need to specify what field within the
> related model you want to search, so 'impresa__fieldname'. (If there are
> multiple fields you need to list each explicitly, using the standard
> double-underscore syntax.)

You was right!

Thanks a lot!

Reply all
Reply to author
Forward
0 new messages