Foreign key filter question

537 views
Skip to first unread message

Larry Martell

unread,
Jan 29, 2014, 5:08:29 PM1/29/14
to django...@googlegroups.com
I have a table that has these 2 foreign keys:

target_name = models.ForeignKey(Target)
wafer = models.ForeignKey(Wafer)

Both Target and Wafer are defined the same:

name = models.CharField(max_length=40, db_index=True, unique=True)

When filtering by wafer I can do this:

wafer__name__icontains='foo'

But when I try to do the same with target, if I do this:

target__name__icontains='foo'

I get:

FieldError Cannot resolve keyword 'target' into field. And in the
choices it shows:

target_name

And if I do:

target_name__icontains='foo'

I get:

Related Field has invalid lookup: icontains

How can I do foreign key filtering using icontains on this field?

Will A

unread,
Jan 29, 2014, 5:28:30 PM1/29/14
to django...@googlegroups.com
Try
target_name_name__icontains='foo' or update the foreign key definition.
 



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY6%3DAOjhYssUYWNQDk-txNvZTfv4RQOZeCSd%2Bb1qQ0NvSA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Larry Martell

unread,
Jan 29, 2014, 9:48:42 PM1/29/14
to django...@googlegroups.com
On Wed, Jan 29, 2014 at 5:28 PM, Will A <can4...@gmail.com> wrote:
> Try
> target_name_name__icontains='foo' or update the foreign key definition.

target_name__name__icontains is what was needed.

Thanks.
> https://groups.google.com/d/msgid/django-users/CAK8f%2Bfr2DPpqwh7j4HBZ8ia-YfmpYTTduLzKqbTeNnvz%3DDKd5g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages