as a part of a project I'm working on, I'm trying to build an hierarchical data structure of objects from different types.
I used django-mptt
for it, which promises to handle trees in a smart way with fast queries.
The problem is, that I have multiple models that needs to participate in this data tree, so I used generic relation in order to store the required data.
A snippet of the model I built:
class CPNode(MPTTModel):
content_type = models.ForeignKey(ContentType, null=True, blank=True)
object_id = models.PositiveIntegerField(null=True)
content_object = GenericForeignKey('content_type', 'object_id')
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
...
This gives me what i want, except of the query issue.
I figure that to query all the data will cost multiple queries (each time I would like to get the content_object itself).
Does anyone has an idea of how I can maintain this structure, and at the same time being able to get all the data in a scalable query?