J
J
Jekson2020-05-27 13:47:48
Django
Jekson, 2020-05-27 13:47:48

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)


Is it possible to pull out info if I want to look at ParentCategory for all modules?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-05-27
@Lepilov

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 modules
well, 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 question

Ask a Question

731 491 924 answers to any question