繁体   English   中英

在这种情况下,如何修复 django 中的 UnicodeDecode 错误?

[英]How to fix UnicodeDecode error in django in this scenario?

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.

这是我的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"

这是我的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"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM