On Jun 12, 8:54 pm, Rana <rd4...@gmail.com> wrote:
> Hi,
>
> I am trying to modify a blog and article model that will both display
> data from a related products model. I read that the way I should do
> this is through the ContentTypes framework and generic foreign
> relations. I would be grateful for some guidance on how to do this.
> I've read the documentation on 
> thehttp://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/
> website, but I am struggling with how to relate it to what I need to
> do.
>
> I have something like this presently:
>
> articles/models.py
> ---------------------------------------
> class Article(models.Model):
>         author = models.ForeignKey(User, related_name='article_author')
>         headline = models.CharField(max_length=256)
>         publish_content = models.TextField(blank=True)
>         ...
>         related_product = models.ManyToManyField('RelatedProduct', null=True,
> blank=True)
>
> class RelatedProduct(models.Model):
>         product_name = models.CharField(max_length=256)
>         product_link = models.TextField(max_length=512)
>
> blogs/models.py
> ----------------------------------------
> class Blog(models.Model):
>         name = models.CharField(max_length=128)
>         long_description = models.TextField()
>         short_description = models.TextField()
>
> I would like to modify this so that I can have the related products
> from articles also available in my Blog class and the related products
> table should be the same between Article class and Blog class, i.e. I
> do not want to have two instances of the RelatedProduct class.
>
> Thank you for any help you can offer.
>
> Rana

You don't need generic relations here, just add a related_product
ManyToMany field do the Blog model in exactly the same way as you did
for the Article model.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to