Sort films by number of comments
topMovie = Movie.objects.annotate(
num_comments=Count('Comments')).order_by('-num_comments')
model.py:
class Movie(models.Model):
Title = models.CharField(max_length=200)
Year = models.CharField(max_length=25, blank=True)
Rated = models.CharField(max_length=10, blank=True)
class Comment(models.Model):
comment_text = models.CharField(max_length=200)
movie_id = models.ForeignKey(
Movie, on_delete=models.CASCADE, related_name='Comments')
pub_date = models.DateTimeField(blank =True,default = now)
how to transfer the time frame to display this field
topMovie = Movie.objects.annotate(
num_comments=Count('Comments')).order_by('-num_comments')
within the specified time frames