Hey Philip,

while I can't help you with your actual implementation I wanted to link you 
to this presentation abuot the topic, it's worth time spend I think ...

https://www.youtube.com/watch?v=CRxjoklS8v0&index=7&list=PLY_che_OEsX3aZo5RttI6Fj2XZ7nTjhBu

recursive models are tricky, especially to query afterwards - your example 
might be not super complicated (yet) but still, I recommend the video...

Marius

Am Donnerstag, 9. August 2018 14:42:13 UTC+2 schrieb Phlip Pretorius:
>
> 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/bc512a99-625d-4ac1-8a2d-0ffd4a5692be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to