I have two models: PostType1, PostType1.
class PostType1(models.Model):
...
created_date = models.DateTimeField(_('created date'), blank=True, null=True)
class PostType2(models.Model):
...
publish_date = models.DateTimeField(_('publish date'), blank=True, null=True)
I make a query for both getting:
posts_type1 = PostType1.objects.all()
posts_type2 = PostType2.objects.all()
I know how to chain them:
posts = chain(posts_type1,posts_type2)
I’m looking for a way to sort them by date descending.
Is this possible ? Or shall I look to raw sql?
So, if your plan is to sort the union of the two querysets, you have to use the
sortedmethod. I would go for something like: