Answer the question
In order to leave comments, you need to log in
How to filter MPTTModel by related models?
There are models:
class Place(MPTTModel):
name = models.CharField(_('name'), max_length=200)
parent = TreeForeignKey(
'self', null=True, blank=True, related_name='children',
verbose_name=_('parent'), db_index=True, on_delete=models.CASCADE
)
class Product(models.Model):
category = TreeForeignKey(
Category, related_name='products', verbose_name=_('category'), db_index=True, on_delete=models.CASCADE
)
name = models.CharField(_('name'), max_length=200)
place = TreeForeignKey(
Place, related_name='products', verbose_name=_('product place'), db_index=True, on_delete=models.CASCADE
)
places = Place.objects.filter(products__category=self.category)
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