我对 Django 很陌生。我有以下代码:
class ModelA(models.Model):
name = models.CharField(max_length=30)
class ModelB(models.Model):
name = models.ManytoManyField(ModelA)
colour = models.CharField(max_lenght=30)
iob = ModelB.objects.filter(name=name)
现在,这很好用:
for i in iob:
print i.colour
我想做类似的事情:
for i in iob:
print i.name
但这肯定行不通。它输出如下:
<django.db.models.fields.related.ManyRelatedManager object at 0x30a2e50>
我想打印名称的值。我该怎么做呢?