Reputation: 12177
I have two models like this:
class Foo():
name = CharField
frequency = IntegerField
class Bar():
thing = ForeignKey(Foo)
content = TextField
I want to get a queryset that will be Bar
objects sorted by a range of Foo
objects. It obviously doesn't work, but it illustrates what I need.
Foo.objects.order_by('-frequency')[0:10].bar_set.all()
Upvotes: 0
Views: 34
Reputation: 1966
if I am getting right what would you like to achieve, try this:
objs = Bar.objects.filter(thing__pk__in=Foo.objects.all().order_by('-frequency').values_list('pk', flat=True)[:10])
Upvotes: 1