So let's say I have the following models in Django:
class Review(models.Model):
datetime = models.DateTimeField(("Date"), default=timezone.now)
class Rating(models.Model):
datetime = models.DateTimeField(("Date"), default=timezone.now)
And my view looks like this:
def get_page(request, id_slug):
context_dict = {}
reviews = Review.objects.filter(attribute=id_slug).order_by('-datetime')
ratings = Rating.objects.filter(attribute=id_slug).order_by('-datetime')
context_dict['reviews'] = reviews
context_dict['ratings'] = ratings
return render(request, 'page.html', context_dict)
What I want to do is make a query set that would include both Review and Rating objects, ordered by the datetime attribute, so something like:
activity = reviewsANDratings.order_by('-datetime')
context_dict['activity'] = activity
What would be the best way to achieve this?
Thank you!