ValueError:"<Entry:django the newest techology>" need to have a value for field 'id' before this many-to-many relationship can be used
因為entry沒有被寫入到數據庫,訪問它的authors屬性會有問題
解決辦法:
先設置好Entry對象的其他非空屬性,並保存,再設置多對多關系:
entry = Entry()
entry.headline = 'headline'
entry.body_text = "body text"
...
entry.save()
entry.authors.add(author)
ValueError:"<Entry:django the newest techology>" need to have a value for field 'id' before this many-to-many relationship can be used
因為entry沒有被寫入到數據庫,訪問它的authors屬性會有問題
解決辦法:
先設置好Entry對象的其他非空屬性,並保存,再設置多對多關系:
entry = Entry()
entry.headline = 'headline'
entry.body_text = "body text"
...
entry.save()
entry.authors.add(author)
entry.save()