I have below queryset in my code.
new_date = date.today() - timedelta(days=7)
most_viewd_list = mytable.objects.filter(show_on_website=True).order_by('-most_viewd')
new_list = most_viewd_list.filter(date_created__gte=new_date)
Now, i want to create a new list (results_list) which will have new_list rows at the beginning followed by most_viewed_list.
I have tried the options mentioned in How to combine 2 or more querysets in a Django view?, but none of them are working.
I tried below option...
from itertools import chain
result_list = list(chain(new_list, most_viewd_list))
But with this option if i use result_list.count(), it is throwing an error.
And with results_list = new_list | most_viewd_list option, i am not getting the desired result.
Can anyone tell me how i can create a list which will have new_list rows followed by most_viewed_list rows.
Thanks