Answer the question
In order to leave comments, you need to log in
How to display number of filtered descendants in mptt?
There are following models using django-mptt:
from django.db import models
from mptt.models import MPTTModel, TreeForeignKey
# жанры
class Genre(MPTTModel):
name = models.CharField(max_length=255, unique=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
class MPTTMeta:
order_insertion_by = ['name']
# статьи
class Article(models.Model):
...
genre = TreeForeignKey(Genre, on_delete=models.CASCADE)
published = models.BooleanField(default=False)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question