-1
所以問題是我無法從窗體保存ManyToManyField。無法保存ManyToManyField
forms.py
class addGoods(forms.Form):
...
permission = form['permission'],
...
models.py
class Add_good(models.Model):
...
permission = models.ManyToManyField(Permission, related_name="+")
...
views.py
if request.method == "POST":
form = addGoods(request.POST)
if form.is_valid():
form = form.cleaned_data
newGood = Add_good(permission = form['permission'])
我試圖做這樣的事情,但也有錯誤
views.py
if request.method == "POST":
form = addGoods(request.POST)
if form.is_valid():
form = form.cleaned_data
newGood = Add_good(permission = form['permission'])
to_do_list = newGood.save(commit=False)
for permis in form['permission']:
to_do_list.permission.add(permis)
to_do_list.save()
newGood.save_m2m()
回溯:
Exception Type: TypeError at /goods/add
Exception Value: 'permission' is an invalid keyword argument for this function
什麼是錯誤? – khajvah
@khajvah加追蹤 –
那麼,錯誤是關於不同的問題。你還沒有發佈足夠的代碼來找到它。 「許可」來自哪裏? – khajvah