Django OneToOne field problem

18 views
Skip to first unread message

Satinderpal Singh

unread,
Jun 12, 2014, 2:54:48 PM6/12/14
to greatdevelopers, django-users
Suppose there are two tables defined in Django models:

class Link(models.Model):
links = models.CharField(max_length=50 ,blank=True)

and

class Content(models.Model):
link = models.OneToOneField(Link, primary_key=True)
title = models.CharField(max_length=50, blank=True)
content = models.CharField(max_length=1000, blank=True)
footer = models.CharField(max_length=150, blank=True)

In the above table "Content" the OneToOne field contains the Link.id
attribute of the
table"Link", but how could i get it as, Link.links.

--
Satinderpal Singh
http://satindergoraya91.blogspot.in/

Max Demars

unread,
Jun 12, 2014, 3:34:12 PM6/12/14
to django...@googlegroups.com, greatde...@googlegroups.com
You will have to do content.link_set to retrieve the Link model related to the Content model instance.

See: https://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward
Reply all
Reply to author
Forward
0 new messages