There is a model of units
class Subdivision(models.Model): name = models.CharField('Наименование', max_length = 200) parent = models.ForeignKey('self', null=True, blank=True) The data is output using the query subdivision = Subdivision.objects.all() , in an unsorted form. For example, there is data in the database:
+ ---- + ------------------------ + -------- + | id | name | parent | + ---- + ------------------------ + -------- + | 1 | Management | null | | 2 | Production Department | 1 | | 3 | Accounting | 1 | | 4 | Production workshop | 2 | + ---- + ------------------------ + -------- +
All this is displayed as:
- Control
- Production Department
- Accounting
- Manufacturing facility
And you need to (keeping the hierarchy):
- Control
- Production Department
- Manufacturing facility
- Accounting
Those. the first is the subdivision with the parent field zero, then the subdivisions, then the subsidiary subdivisions of the subsidiary, and so on Is it possible to implement this sorting with django?