Reverse lookup in search_fields on Admin

113 views
Skip to first unread message

Emanuel

unread,
Oct 21, 2014, 2:36:45 PM10/21/14
to django...@googlegroups.com
Hello all!

I have this models:

class Article(models.Model):
  name = models.CharField(...)

class Sale(models.Model):
  ...

class SaleItems(models.Model):
  article = models.ForeignKey(Article)


And the Admin:
class SaleAdmin(admin.ModelAdmin):
  search_fields = ('...', < and here is the problem >

I want that in the Sale Index Page look all the sales that have sold the article "A"

To accomplished that I tried: 'saleitems__article__name' and it throws the following error:
"
Related Field got invalid lookup: icontains"

Is there a way to do the reverse lookup in search_fields?

Thanks id advance


Collin Anderson

unread,
Oct 23, 2014, 8:11:37 AM10/23/14
to django...@googlegroups.com
Hello,

Your code looks right. Do you have other things in search_fields?

Thanks,
Collin

Emanuel

unread,
Oct 23, 2014, 12:45:52 PM10/23/14
to django...@googlegroups.com
Hi.

Yes, I do have another fields. And thanks a lot. I was focus on that particular field that I forgot to see that I had another relation in search_fields wich I was not  using the lookup. It works now.

Thanks
Reply all
Reply to author
Forward
0 new messages