Ok, just did that and it worked (had to delete and re-create the db). Thank 
you very much for your quick reply.

One last question though, just for curiosity, is there no way to create 
such cyclic relationships? If so, how?


El jueves, 13 de marzo de 2014 03:41:05 UTC-5, Erik Cederstrand escribió:
>
> Den 13/03/2014 kl. 06.34 skrev Santiago Palacio Gómez 
> <spal...@gmail.com<javascript:>>: 
>
>
> > Hi everyone, 
> > 
> > I'm a Django newbie, and I was following the tutorial for 1.6, creating 
> a new app where one of the models is self-referencing. They ask to, in 
> manage.py shell, create an instance of the model. But, as my model has a 
> self reference foreign key, I can't pass any object to the key. I also 
> would not like to leave it Nullable, as it may cause errors. Rather, I'd 
> just like to pass 'self' as the reference, this is, the key it references 
> should be its self key. 
> > 
> > Is it possible? Thanks in advance! 
>
> What is meant in the tutorial is most definitely not that the model 
> ‘instance’ should reference itself, but rather that the instance should 
> reference another instance of the same type, i.e. a parent-child 
> relationship. Something like: 
>
> class Person(models.Model): 
>   mother = models.ForeignKey(’self', null=True) 
>   father = models.ForeignKey(’self', null=True) 
>
> You need to keep the field nullable because something must be root of the 
> relationship structure (unless you want to create only cyclic 
> relationships, which is not recommended for family structures...). To 
> create a relationship do this: 
>
> eve = Person.objects.create() 
> adam = Person.objects.create() 
> abel = Person.objects.create(mother=eve, father=adam) 
>
>
> Erik

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/acbebc7a-60c5-4950-a3ac-51af5b34bc0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to