Answer the question
In order to leave comments, you need to log in
How to display children in django?
There is a model
class Person(model.Model)
last_name = models.CharField(max_length=30, verbose_name='Фамилия')
first_name = models.CharField(max_length=30, verbose_name='Имя')
middle_name = models.CharField(max_length=30, verbose_name='Отчество')
unit = models.ManyToManyField(Unit, verbose_name='Подразделение')
position = models.ManyToManyField(Position, verbose_name='Должность')
chief = models.ForeignKey('self', verbose_name='Руководитель', blank='True', null='True', related_name='chiefname')
Answer the question
In order to leave comments, you need to log in
like this in my opinion
PS: only in my opinion a very strange data structure is obtained. A person can be in several departments, in several positions, and the department and position are not connected in any way. but under the direction of only one other person.
I think it makes more sense to do something like
class Person(...):
...
department = models.ManyToManyField('Department', verbose_name='подразделение', throught='PersonInDepartment')
class Department(..):
chief = models.ForeignKeyField(Person,....)
...
class PersonInDepartment(...):
person = ForeignKey
department = ForeignKey
position = ForeignKey
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question