Skip to content
Advertisement

Django, have model to be related to many instances of itself

I have a model:

I want it to have a sub_industries field that will hold all of its sub industries, which should be instances of Industry model.

I cannot be ManyToMany because each industry has only one parent industry.

Advertisement

Answer

You can add a ForeignKey to itself with:

You can use NULL/None to express that an industry has no parent.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement