Answer the question
In order to leave comments, you need to log in
How to remove articles from a category on 1 page?
Good afternoon! How to display articles from the movies category on the 1st page, and display articles from the TV series category from the bottom?
I haven't been able to figure this out for a few days now.
#model
#Категории
class Category ( models.Model ):
name = models.CharField ( max_length = 32 )
slug = models.SlugField( blank=True )
def __str__( self ):
return self.name
def get_absolute_url(self):
return reverse("category_detail", kwargs={"category_slug": self.slug})
# Посты
class News ( models.Model ):
Category = models.ManyToManyField( Category )
Avtor = models.ForeignKey( Avtor,on_delete=models.CASCADE,blank=True )
name = models.CharField( max_length = 120 )
slug = models.SlugField(blank=True)
post = RichTextField()
descript = models.TextField( max_length = 500)
tag = models.TextField()
date = models.DateTimeField()
img = models.ImageField(upload_to=image_folder,blank=True)
def __str__( self ):
return self.name
def get_absolute_url(self):
return reverse("post_detail", kwargs={"news_slug": self.slug})
Answer the question
In order to leave comments, you need to log in
In vyuhe it was necessary to write.
def News_views(request):
films_news = News.objects.all().filter(Category=1#ID Категории)
serials_news = News.objects.all().filter(Category=2#ID Категории)
context = {
...
'films': films_news,
'serials': serials_news,
...
}
return render(request,'news/wrapper.html',context)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question