1👍
✅
From the Django Docs
By default, a QuerySet will not eliminate duplicate rows. In practice, this is rarely a problem, because simple queries such as Blog.objects.all() don’t introduce the possibility of duplicate result rows. However, if your query spans multiple tables, it’s possible to get duplicate results when a QuerySet is evaluated. That’s when you’d use distinct().
You need to apply the distinct()
method, So you may need to do :
print Offer.objects.all().filter(shop__city=1).distinct()
1👍
Since you are placing a join on 3 table. Its going to return you the result with the offers for all the shops in that city. Try to do this
Offer.objects.all().filter(shop__city=1).distinct()
- [Answered ]-Django-allauth – RESTful API return all email address belonging to a user
- [Answered ]-Django template tag, python timezone aware dates different results
- [Answered ]-How to delete a slice
- [Answered ]-Django template: submit form after file upload
- [Answered ]-Using ManyToManyFields() with Django
- [Answered ]-Problems setting up Django with Mongo db in windows 8
- [Answered ]-Django, Extend BaseUserManager,
- [Answered ]-OnetoOneField connection , can't access the related information , django
Source:stackexchange.com