0

I am starting to create a webapp using Django and MongoDB. Everything is working fine when I create a model and save it into the Database. Now, I do a "Class.objects.get()" to get the object I need from my DB and I have one field called "media" which is a ListField(). I had tried doing either:

Concert.media.append(list)

or

Concert.media.extend(list)

and then

Concert.save()

This is my "Concert" object in my models.py:

class Concert(models.Model):
main_artist = models.CharField(max_length=50)
concert_id = models.AutoField(primary_key=True)
openers = ListField(EmbeddedModelField('Opener'))
concert_date = models.DateField()
slug = models.SlugField(unique=True)
media = ListField()

And when I go to see the results in does not update the object. No values where saved. If someone can help me I going to give a super cyber fist bump.

4

1 回答 1

1

Concert是一个类,而不是一个实例。您无法保存课程。您需要创建该类的一个实例并保存它。就像是

c = Concert()
c.media.append(list)
c.save()

(顺便说一句,这list是一个不好的变量名,因为 list 是 python 中的一种类型。永远不要使用类型作为变量名(尽管每个人都曾在某一时刻犯过这一点,包括我在内。))

于 2013-03-07T00:02:52.187 回答