开发者

Why is save not working in Django?

I'm using manage.py shell and run something like this:

d=Document.objects.get(pk=1)
d.scores  
{1:0,2:0,3:0}  
d.scores[1]=5
d.scores
{1:5,2:0,3:0} 
d.save()

But viewing d in the database reveals that it hasn't been updated. What am I doi开发者_如何转开发ng wrong?? I checked out what's here, but d is definitely a Document instance.

If it helps, models.py looks like this:

from django.db import models

class Document(models.Model):
    fileName=models.CharField(max_length=200)    
    fileUrl=models.CharField(max_length=200) 
    scores={1:0,2:0,3:0}  


Your 'scores' class variable isn't an instance of any of Django's *Field classes. I would imagine the 'scores' field isn't even on the table in the DB, since the field classes are what defines all of that, and what gets saved to the DB, among other things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜