I'm coding a news website.I have 'category' in News model.
Now I want to get all the news in one of the categories named 'opinion'. But get: invalid literal for int() with base 10: 'opinion'
here is part of my News model:
class News(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="cate", blank=True, verbose_name='分类')
here is my Category model:
class Category(models.Model):
name = models.CharField(max_length=40) # 分类名
class Meta:
verbose_name = "分类"
verbose_name_plural = verbose_name
def __str__(self):
return self.name
here is part of my view:
class NewsView(View):
def get(self, request):
opinion_news = News.objects.filter(category="opinion")
return render(request, 'index.html', {
'opinion_news': opinion_news,
})
here is part of my index.html
{% for opinion in opinion_news %}
<li class="media">
<h>{{opinion.title}}</h>
</li>
{% endfor %}
Any friend can help?Thank you so much!