Suppose I have a model call MyModel
defined as below
class MyModel(models.Model):
fk = models.ForeignKey('AnotherModel')
rank = models.FloatField()
I wish to create a query set for serialization so that instances with instance.fk.other_fk_id
in some set comes before the ones that don't and then sorted by decreasing rank.
So I wish to join
a = MyModel.objects.filter(fk__other_fk_id__in=some_set).order_by('-rank')
and
b = MyModel.objects.exclude(fk__other_fk_id__in=some_set).order_by('-rank')
sequentially so that a comes before b when it's handed to the serializers. Any idea on how to achieve this functionality efficiently? (let's say there is 50 instances in a
and 200000 instances in b
so I cannot directly concat those two as lists).
The end goal is to feed it into a custom serializer w/ pagination, say, to present in a webpage.