Saturday, October 17, 2009

Linking items from the same model

Hi

I am trying to create a model for Article site. I want to link each article with 3-5 related articles, so what I am thinking of is creating code this way:

    class Article (models.Model):
        # Tiny url
        url = models.CharField(max_length = 30, unique=True)
        is_published = models.BooleanField()
        author = models.CharField(max_length = 150)
        title = models.CharField(max_length = 200)
        short_description = models.TextField(max_length = 600)
        body = tinymce_models.HTMLField()
        related1 = models.ForeignKey(Article)
        related2 = models.ForeignKey(Article)
        related3 = models.ForeignKey(Article)

But not sure if it's possible to make a foreign key relation to the same model. Also if for example, I will decide to bind 6, 7 articles together, how that will work, do I have to write related4, 5, 6....in the model? I want to have more common solution, so if I binding more articles, I don't need to redefine code again and again

What I am thinking of is not to extend Article models with related fields.. (It looks ugly)
Maybe it worth creating another model?
For example: ArticleSet

But how to define there unrestricted list (without limit of items)..Could you suggest a way?

Thanks in advance

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate