0
我有以下代碼;從一個django模型到另一個節省一個多對多的字段
# check whether it's valid:
if form.is_valid():
travel = form.save(commit=False)
travel.user = request.user
travel.save()
form.save_m2m()
travel_2 = Travel()
travel_2.from_city = travel.to_city
travel_2.to_city = travel.from_city
travel_2.from_when = travel.to_when
travel_2.commission = travel.commission
travel_2.user = travel.user
travel_3 = travel_2.save()
,基本上可以節省一個旅行對象,然後將該對象旅行到另一個旅遊對象副本(travel_2)
我怎麼保存多對多場「類別」,從旅遊到travel_2?
很多很多場在該行被設置:
form.save_m2m()