I want to order the model objects in descending order, how am I supposed to go about doing that using the field number
in my model class.
Here is my views.py:
class SeasonDetailView(DetailView):
model = CartoonSeason
template_name = "episode_list.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["episodes"] = Episode.objects.filter(season=self.object)
return context
class EpisodeDetailView(DetailView):
model = Episode
template_name = "episode.html"
And this is my models.py:
class Episode(models.Model):
season = models.ForeignKey(CartoonSeason, on_delete=models.CASCADE)
number = models.IntegerField()
cover = models.URLField(max_length=300, blank=True, null=True)
name = models.CharField(max_length=200, blank=True, null=True)
description = models.TextField(blank=True, null=False)
link = models.URLField(max_length=300, blank=True, null=True)
published = models.DateField(auto_now_add=True, blank=True, null=True)
class Episode(models.Model):
season = models.ForeignKey(CartoonSeason,on_delete=models.CASCADE)
number = models.IntegerField()
cover = models.URLField(max_length=300, blank=True, null=True)
name = models.CharField(max_length=200, blank=True, null=True)
description = models.TextField(blank=True, null=False)
link = models.URLField(max_length=300, blank=True, null=True)
published = models.DateField(auto_now_add=True,
blank=True,null=True)
class Meta:
verbose_name = _("Episode")
verbose_name_plural = _("Episodes")
ordering = ["season"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.