Have a look at the following code snippet:
def post_proposals(count):
post_elements = chain(
PostModel1.objects.all(),
PostModel2.objects.all(),
PostModel3.objects.all(),
)
post_elements_list = list(post_elements)
post_proposals = random.sample(post_elements_list, count)
return post_proposals
Where it's requiered to generate a list of proposals from 3 different Post tables, how to optimize a disgn flaw like this? Already came accorss the idea to build a Index table where all PKs of all my PostModel{1..3} are stored, so that I just have to query 1 table instead of three. Does smb. have a practical idea on how to solve this or at least optimizing it?