我有以下型號:如何將queryset添加到ManyToMany關係?
class EnMovielist(models.Model):
content_ID = models.CharField(max_length=30)
release_date = models.CharField(max_length=30)
running_time = models.CharField(max_length=10)
actress = models.CharField(max_length=300)
series = models.CharField(max_length=30)
studio = models.CharField(max_length=30, null=True)
director = models.CharField(max_length=30)
def __str__(self):
return self.content_ID
class EnActress(models.Model):
name = models.CharField(max_length=100, null=True)
movielist = models.ManyToManyField(EnMovielist, related_name='movies')
def __str__(self):
return self.name
我有錯誤,當我嘗試這在Django殼,
b = EnActress.objects.values_list('name', flat=True)
a = EnMovielist.objects.filter(actress__contains=b).values_list('content_ID')
b.movielist.add(a)
AttributeError: 'QuerySet' object has no attribute 'movielist'
我如何Django的查詢集添加到許多一對多場? 我不知道爲什麼會發生這種情況..任何幫助表示讚賞! :)
如果你仍然需要使用查詢集,那麼你不應該使用'values_list',你顯示的代碼沒有多大意義,我不知道它試圖實現什麼 – Sayse