Reputation: 2249
I have such models:
class Parent(models.Model):
name = models.CharField(max_length=31)
class Child(models.Model):
name = models.CharField(max_length=31)
value = models.FloatField()
parent = models.ForeignKey(Parent, related_name='children')
I need to sort Parent
instances by children values, but consider only child with defined name.
What is the best way to do this?
Upvotes: 0
Views: 48
Reputation: 599610
You can pretty much do it as you describe:
Parent.objects.filter(child__name='defined name').order_by('child__value')
Upvotes: 2