Django: relations between two objects of the same model
I have created this model:
class Process(models.Model): name = models.CharField('Process name', max_length=50, unique=True) owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, max_length=50, null=True, verbose_name='Process owner')
I want to create multiple processes and from those build a hierarchy. Here is a hierarchy model:
class Hierarchy(models.Model): name = models.ForeignKey('process.Process', on_delete=models.CASCADE, verbose_name='Sub process name') name = models.ForeignKey('process.Process', on_delete=models.CASCADE, verbose_name='Main process name') order = models.IntegerField('Process order', default='1')
Obviously this doesn't work as the 'name' fields in hierarchy model interfere with each other. I wouldn't want to create models MainProcess and SubProcess as some SubProcesses might have more SubProcesses etc.
What would be the right way to build this type of model/hierarchy? This might be very basic issue, but I couldn't find any related issues to apply a solution from, so any help would be appreciated.