I am really stuck in this problem for a while. this is really challenging
for me. .. tough one...
i have two models. Location and Rate.
each location has rates, possibly multiple rates.. let me give you my
models:
class Location(models.Model):
name = models.TextField()
adres = models.TextField()
class Rate(models.Model):
location = models.ForeignKey(Location,related_name='locations_rate')
rate = models.IntegerField(max_length=2)
the case is:
I am trying to write the sort function which is called when user in resultpage
the result items sorts e.g. by rate. then the results should be sorted
ascendingly ordered by rate.
I tried this:
locations =
Location.objects.filter(**s_kwargs).order_by('-locations_rate__rate')
but this is giving me duplicate items. then i tried this: locations =
Location.objects.filter(**s_kwargs).distinct('id').order_by('-locations_rate__rate')
but i am getting error message saying this wont work as i read in every forum.
what can i do so that i can sort the items ordering by rates and keeping them
distinct set?
please help me
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.