首先,我没有进入网络编程。我碰到了django并阅读了一些关于模型的内容。我被下面的代码(从djangoproject.com)很感兴趣:Django模型字段如何工作?
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))
通过我的蟒蛇,FIRST_NAME的理解和姓氏是类变量,对不对?在代码中如何使用它(因为我猜想设置Person.first_name或Person.last_name会影响所有Person实例)?为什么这样使用?
丹科舍恩安迪! – Geo 2009-02-01 13:00:00
这里有一些很好的链接,但是“在这一点上它们本质上表现为实例变量”是一点手势,并非真正准确(或者至少没有解释任何东西)。 – 2009-02-01 18:44:16