Hello there,
this is my first question in django forum.
I have two modela Publication and Article as follow.
class Publication(models.Model):
title = models.CharField(max_length=30)
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication,
related_name="published_article",
through='articles_publication',
through_fields=('article', 'publication'))
In Article model I have ManyToMany
publications field which is pointing to the article_publication model which is as follow.
class articles_publication(models.Model):
articles_publication_id = models.AutoField(primary_key=True, db_column='article_publication_id')
article = models.ForeignKey(Article, on_delete=models.SET_NULL, null=True)
publication = models.ForeignKey(Publication, on_delete=models.SET_NULL, null=True)
Now, In this scenario, we are creating an individual model to maintain ManyToMany
relation between Article and publication. So, why we should have a field publications
in Article Model. Following Article model will perform the same task.
class Article(models.Model):
headline = models.CharField(max_length=100)
Specifying the ManyToMany
field provides any advantage?
Thanks in advance.