django - how to query this?
i have two tables called Location and Rate.
Rate table has these items:
von_location is Foreignkey to Location table.
i want to get a location for a wanted rate. if i search for a location
with romantic 2, i am getting location with id 5. this is fine. but if i
also search for a location with romantic 3, i am also getting the location
with id 5. but i want this logic:
if one locations have two rates, get the latest one. how can i do this in
django?
my models are:
class Location(models.Model):
name = models.TextField()
adres = models.TextField()
class Rate(models.Model):
von_location =
models.ForeignKey(Location,related_name='locations_bewertung')
bewertung = models.IntegerField(max_length=2)
romantic = models.IntegerField(max_length=2)
priceleistung = models.IntegerField(max_length=2)
datum = DateTimeField(auto_add_now=True)
i dropped some columns which are not relevant to my question
i tried this:
locations =
Location.objects.filter(**s_kwargs).order_by('locations_bewertung').distinct('locations_bewertung')
i am still getting the same location for both queries. 2, and 3.
No comments:
Post a Comment