How to add descriptive attribute when using ManyToManyField in django?
I am just trying to learn django. Sorry if this is a silly question. https://docs.djangoproject.com/en/5.0/topics/db/examples/many_to_many/ I was reading this documentation on ManyToManyField, it talks about two models Articles and Publishers. ` from django.db import models
class Publication(models.Model):
title = models.CharField(max_length=30)
class Meta:
ordering = ["title"]
def __str__(self):
return self.title
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
class Meta:
ordering = ["headline"]
def __str__(self):
return self.headline`
Articles has a ManyToManyField 'publishers'. In the document it says the association table is created by django. Now how do I add descriptive attributes for example 'published date'?
I have read this documentation. I want to know if there is a way to add descriptive attribute when using ManyToManyField.
Just add published_date field to Article model
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
published_date = models.DateTimeField(auto_now_add=True)