Django Model: many-to-many or many-to-one?

Posted by knuckfubuck on Stack Overflow See other posts from Stack Overflow or by knuckfubuck
Published on 2010-04-23T23:37:24Z Indexed on 2010/04/23 23:43 UTC
Read the original article Hit count: 271

Filed under:
|

I'm just learning django and following a tutorial. I have a Link and a Bookmark. Unlike the tutorial I'm following, I would like a link to be associated with only one Bookmark, but a Bookmark can have multiple links. Is this the way to setup the model?

class Link(models.Model):
    url = models.URLField(unique=True)
    bookmark = models.ForeignKey(Bookmark)

class Bookmark(models.Model):
    title = models.CharField(maxlength=200)
    user = models.ForeignKey(User)
    links = models.ManyToManyField(Link)

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models