简体   繁体   中英

Django Mongodb ListField not saving or updating

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.

Concert is a class, not an instance. You can't save a class. You need to make an instance of the class and save that. Something like

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

(btw, just as a note, list is a bad variable name because list is a type in python. Never use types as variable names (though everyone is guilty of this at one point or another, including me.))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM