I want to build a one-to-many recursive foreign key on a table in Django. The concept is something like this:
Table: staff/person staff number Surname Firstnames Supervisor 4637 Zondo Julien 859076 Vanderbildt John 4637 That is, Julien Zondo is John Vanderbildt's supervisor and to enter the staff number in the supervisor field, it must exist in the staff table. Each staff member can have only one supervisor but a person can be the supervisor of many staff members. I have read the documentation at https://docs.djangoproject.com/en/2.1/ref/models/fields/#recursive-relationships but i do not get the gist of it I want to build an index table on three levels where a level 1 index will have no predecessor Level 2 indexes must have a level 1 predecessor and a level 3 index must have a level 2 pedecessor. Can this be done by using recursive relationships or should this be done in a business layer? Here is part of the definition of the model: ============================================================================= Class DecisionIndex(models.Model): """A mechanism to index decision taken by a committee""" IndexCode = models.CharField(max_length=6) IndexDesc = models.CharField(max_length=80, null=False) IndexLevel = models.IntegerField(choices=list(zip(range(1, 4), range(1, 4))), null=False) IndexPredecessor = models.ForeignKey('self', on_delete=models.CASCADE, limit_choices_to={'IdexLevel': 1},) ============================================================================ I get the following error message: no such column: komadm_apps_decisionindex.IndexPredecessor_idno such column: Any help will be welcome. Regards, Phlip -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/083eaa35-9b60-40ae-9056-7a71a17c79fc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.