首先,我不是网络编程.我碰到了django并且读了一些关于模特的内容.我对以下代码感兴趣(来自djangoproject.com):
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
def __str__(self):
# Note use of django.utils.encoding.smart_str() here because
# first_name and last_name will be unicode strings.
return smart_str('%s %s' % (self.first_name, self.last_name))
Run Code Online (Sandbox Code Playgroud)
根据我对python的理解,first_name和last_name是类变量,对吗?如何在代码中使用(因为我猜设置Person.first_name或Person.last_name会影响所有Person实例)?为什么这样使用?