0
我想插入單個的聲音到Room對象中,這樣我就可以插入到數據庫中。我該怎麼做呢?將manytomany字段插入db
我試過了,Room(squawk = squawk object),但這似乎不起作用。
class Squawk(models.Model):
username = models.ForeignKey(User)
message = models.CharField(max_length=160)
time = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return str(self.username) + ' - ' + self.message
class Room(models.Model):
title = models.CharField(max_length=160)
created = models.DateTimeField(auto_now_add=True)
users = models.ManyToManyField(User)
squawks = models.ManyToManyField(Squawk)
def __unicode__(self):
return self.title