Answer the question
In order to leave comments, you need to log in
Is it possible to get the required queryset from this type of connection?
models.py
class Modules(models.Model):
parent_categories= models.ManyToManyField('ParentCategory', related_name='modules', through='ModuleParentCategory')
class ParentCategory(models.Model):
name = ...
class ModulesParentCategories(models.Model):
module = models.ForeignKey('Modules', on_delete=models.CASCADE)
parent_category = models.ForeignKey('ParentCategories', on_delete=models.CASCADE)
primary = models.BooleanField(default=False)
Answer the question
In order to leave comments, you need to log in
It looks like some kind of unnecessary complexity, it will be a pain to work with this, I would simplify everything.
I want to look at ParentCategory for all moduleswell, do it from the other end - select all modules that have a relationship with a specific ParentCategory
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question