Django ORM expression for recursive sum type?

I am making a simple PLM software and the recursive component system is necessary for it.

Specifically, I would like to know if there is any way one can express the data type below with Django ORM; if not what would be the best workaround?

Component ::= Part
           | [Component] (or Set of Components)

I think the problem breaks down into two issues.

  1. How to express sum type with Django ORM
  2. How to express a List of a type with ORM

For the second issue alone, I am using the two Models (or Table); One for the list instance and another for the rows of the lists which have foreign key filed of list instance to indicate which model it belongs to.

However, It seems not that useful for this case; Especially considering querying and forms. What would be the closest expression of the data type above in Django ORM?

Back to Top