A
A
Astrohas2017-07-27 15:45:36
Django
Astrohas, 2017-07-27 15:45:36

How to design the following query on Django ORM?

Good evening! I would like your help with the following:
There are three models:

class Modal(models.Model):
   semething

class Link(models.Model):

    active = models.BooleanField(default=True)
 
    next_modal = models.ForeignKey(Modal, blank=True, null=True)

    parent_modals = models.ManyToManyField(Modal, through='ModalItem', related_name="child_links")

class ModalItem(models.Model):
    modal = models.ForeignKey(Modal)
    ...
    link = models.ForeignKey(Link)

You need to get into the modals associated with a particular modal.
Linking one modal to another is done through the modalItem and LInk tables.
Modal oneToMany ModalItem
ModalItem ManyToOne Link
Link manyToOne Modal
92757d5abf614d659e4fedc827280ca8.png
hmm you need to use the minimum number of requests to get all the modals associated with the given one. With the help of banal recursion, I will get several thousand requests. Monkey patching also works well, but also for 500 requests. Therefore, we need your help! Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sergeev, 2017-07-28
@SergeevAI

Django MPTT ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question