0

I just updated django from 1.8.5 to 1.10. In the old Version i used a filter to search for entries regarding more then one location. For example:

One User has multiple Stores. Each of this Stores has a Reviews Board. Now the User wants to lookup all Stores and their Reviews or specific Groups of Stores.

In Django 1.8.5 i used the following lookup:

all stores

locations = Locations.objects.filter(email=email) 

locations queryset(location1, location2 etc.)

reviews = Reviews.objects.filter(location_id=locations) 

group

reviews = Reviews.objects.filter(location_id=group_content.locations.all()) 

In Reviews the location field is a ForeignKey(Locations) and locations is a Queryset.

This worked just fine. However in 10.10 it appears this functionality is gone. I looked through the new Docs but could not find anything which could replicate the original functionality.

My whole System is built around this functionality, so it would take forever to change everything.

Is there any new Lookup i could use?

models.py (Reviews):

class Reviews(models.Model): location_adress = models.CharField(max_length=3000, default='', blank=True, null=True) location_name = models.CharField(max_length=3000, default='', blank=True, null=True) location_id = models.ForeignKey(LocationData) plattform = models.CharField(max_length=3000, default='', blank=True, null=True) reviewer_name = models.CharField(max_length=3000, default='', blank=True, null=True) reviewer_picture = models.CharField(max_length=3000, default='', blank=True, null=True) review_id = models.CharField(max_length=3000, default='', blank=True, null=True) review_rating = models.CharField(max_length=3000, default='', blank=True, null=True) review_date = models.DateTimeField(auto_now_add=False, auto_now=False, blank=True, null=True) review_text = models.CharField(max_length=3000, default='', blank=True, null=True) review_like_count = models.CharField(max_length=3000, default='', blank=True, null=True) review_share_count = models.CharField(max_length=3000, default='', blank=True, null=True) review_comment_count = models.CharField(max_length=3000, default='', blank=True, null=True) review_image = models.CharField(max_length=3000, default='', blank=True, null=True) next_entry = models.CharField(max_length=3000, default='', blank=True, null=True) seen = models.BooleanField(default=False) unseen_comments_count = models.IntegerField(default=0, null=True) comments = models.ManyToManyField(ReviewComments) scale = models.IntegerField(default=None,blank=True, null=True) def __str__(self): return self.location_name 

modely.py (Locations)

 class LocationData(models.Model): #Location Data group_id = models.CharField(max_length=120, default='', blank=True, null=True) location_id = models.CharField(max_length=120, default='', blank=True, null=True) email = models.EmailField() name = models.CharField(max_length=120, default='', blank=True, null=True) street = models.CharField(max_length=120, default='', blank=True, null=True) street_number = models.CharField(max_length=120, default='', blank=True, null=True) opening = models.DateTimeField(auto_now_add=False, auto_now=True) tel = models.CharField(max_length=120, default='', blank=True, null=True) postal_code = models.CharField(max_length=120, default='', blank=True, null=True) city = models.CharField(max_length=120, default='', blank=True, null=True) country = models.CharField(max_length=120, default='', blank=True, null=True) description = models.CharField(max_length=1120, default='', blank=True, null=True) short_description = models.CharField(max_length=1120, default='', blank=True, null=True) website = models.CharField(max_length=120, default='', blank=True, null=True) location_email = models.CharField(max_length=120, default='', blank=True, null=True) tags = models.CharField(max_length=120, default='', blank=True, null=True) profilbild = models.CharField(max_length=320, default='', blank=True, null=True) titelbild = models.CharField(max_length=320, default='', blank=True, null=True) def __str__(self): #Python 3.3 is __str__ return self.name 

Result:

 >>> from reviews.models import Reviews >>> from locations.models import LocationData >>> l = LocationData.objects.all() >>> Reviews.objects.filter(location_id=l) <QuerySet [<Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>]> >>> Reviews.objects.filter(location_id=l[0]) <QuerySet [<Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>, <Reviews: Bspotted>]> >>> Reviews.objects.filter(location_id=l[1]) <QuerySet [<Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, <Reviews: Roberto American Bar>, '...(remaining elements truncated)...']> 
3
  • If you get some error post it in the question. Commented Aug 14, 2016 at 12:24
  • @Todor no errors, just not the desired result Commented Aug 14, 2016 at 12:28
  • @Todor updated the Result Commented Aug 14, 2016 at 12:30

1 Answer 1

1

l is a queryset, not a single object, so you should do something like that:

Reviews.objects.filter(location__in=l) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.