Thursday, September 12, 2013

Re: [Newbie] Self referencing models

Hello Zoubeida,

models.ForeignKey(self) works (see https://docs.djangoproject.com/en/1.5/ref/models/fields/#foreignkey about it).

What sort of error did you get when trying it ?

Regards,
Xavier Ordoquy.


Le 12 sept. 2013 à 09:44, Zoubeida <zzarkouna@gmail.com> a écrit :

Any help?

Le samedi 8 novembre 2008 07:58:00 UTC+1, sunn a écrit :
How do I make a foreign key to self?

class Page(models.Model):
    title = models.CharField(max_length=128)
    display = models.CharField(max_length=64)
    path = models.CharField(max_length=64)
    sortorder = models.IntegerField()
    parent = models.OneToOneField(Page) #Will not work neither will
    parenttest = models.ForeignKey(Page) #nor
    parenttest2 = models.ForeignKey(self)
    def __unicode__(self):
        return self.display

any help appreciated!

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate