我也嘗試使用append將信息保存到ArrayField。根據這post它應該是可能的,但我不能得到它的工作。我不是創建新的對象,它已經存在,我只是需要更多的信息附加到ArrayField保存到django數據庫
代碼片段:
def isInDatabase(catInfo):
cat = catagories.objects
catName = str(catInfo)
iban = catInfo.getIban()
try:
cat.get(Naam = catName)
except ObjectDoesNotExist:
print catName, 'is not in database'
# NOTE: create catagory
p = cat.create(Naam = catName, Rekening = [iban])
print catName, 'Has been stored in the database with', iban
else:
ibanList = cat.get(Naam = catName).Rekening
editCat = cat.get(Naam = catName)
print catName,'is in db, the following ibans are stored:\n\n', ibanList,'\n\n'
if iban in ibanList:
print iban,'is already in the list\n'
else:
ibanList.append(iban)
editCat.save()
print 'Updated list for',catName,'with -->',iban,'\nlist is now -->', ibanList,'\n'
的editCat.save()
被保存命令那不是儲蓄。
models.py
class catagories(models.Model):
Naam = models.CharField(max_length=10)
Rekening = ArrayField(models.CharField(max_length = 34), blank = True)
def __str__(self):
return self.Naam
所以做什麼修改,我需要得到它保存到數據庫中。我沒有收到任何錯誤,所以腳本運行良好,但不保存到數據庫。
啊isee有道理謝謝! – Kevin