[Fixed]-Many to many relationships with additional data on the relationship

22đź‘Ť

âś…

I recommend you check out the section “EXTRA FIELDS ON MANY-TO-MANY RELATIONSHIPS” in the Django documentation – it covers exactly your question.

1: yes, creating an intermediary model is the way to go.

2: From the documentation: “Unlike normal many-to-many fields, you can’t use add, create, or assignment to create relationships” – Instead, for adding Artist to an Issue, do it from the intermediary model:

some_artist = Artist.objects.get(name='some name')
some_issue = Issue.objects.get(tile='some tite')
IssueArtist.objects.create(artist= some_artist, issue = some_issue, role=1)
👤Hoff

Leave a comment