在调试的时候,突然发现,怎么遍历model字段和字段的值呢?
可以在model的_meta里获取全部字段Model._meta.get_all_field_names()
可以使用__getattribute__(key)
根据key获取value
for x in names:
print x,':',Snippet.objects.all()[0].__getattribute__(x)
在调试的时候,突然发现,怎么遍历model字段和字段的值呢?
可以在model的_meta里获取全部字段Model._meta.get_all_field_names()
可以使用__getattribute__(key)
根据key获取value
for x in names:
print x,':',Snippet.objects.all()[0].__getattribute__(x)