I'm working on a blog. On its first page I want to show 4 random blog posts & 6 latest blog posts!
Here's what I did:
# 4 random posts
data1 = sorted(Blog.objects.all(), key=lambda x: random.random())[:4]
# 6 latest posts (excluding the random ones)
data2 = Blog.objects.exclude(id__in=data1).order_by('-id')[:6]
# all blogs
results = list(chain(data1, data2))
But the above code is raising an error: int() argument must be a string, a bytes-like object or a number, not 'Blog'.
When I remove .exclude(id__in=data1) from data2 everything is working fine, but I need it in order to prevent duplicates.
How can we fix that? Thank You!