queryset迭代

class DB(objects):
    name = models.CharField(verbose_name=u'名', max_length=100)

    class Meta:
        verbose_name = u'db'
        db_table = 'db'


# 方法一
aa = ["a", "b", "c"]
dbs = DB.objects.filter(id__in=(1,2,3))
for n, a in enumerate(aa):
    db_obj = dbs[n]
    db_obj.name = a
    db_obj.save()


# 方法二
aa = ["a", "b", "c"]
dbs = DB.objects.filter(id__in=(1,2,3))
for n, a in enumerate(aa):
    dbs[n].name = a
    dbs[n].save()

方法一和方法二的结果是一样的么?

你可能感兴趣的:(服务器)