Many to many relationships with additional data on the relationship

后端 未结 1 1383
误落风尘
误落风尘 2021-02-12 23:45

I\'m trying to create a django database that records all my comic purchases, and I\'ve hit a few problems. I\'m trying to model the relationship between a comic issue and the ar

相关标签:
1条回答
  • 2021-02-13 00:20

    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)
    
    0 讨论(0)
提交回复
热议问题