Wednesday, January 29, 2014

Foreign key filter question

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?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

No comments:

Post a Comment