I have many classes with same field named
NEW = 'new'
ACTUAL = 'actual'
DELETE = 'delete'
STATE_CHOICES = (
abstract = True
state = models.CharField(
name 'STATE_CHOICES' is not defined
>>> c = ChildClass.objects.all()
(('new', 'new'), ('actual', 'actual'), ('delete', 'delete'))
ChildClass(UsefullAbstractClass): state = models.CharField( max_length=100, choices=UsefullAbstractClass.STATE_CHOICES)
Variables defined in the class definition are class variables; they are shared by all instances. To create instance variables, they can be set in a method with self.name = value. Both class and instance variables are accessible through the notation
You can access it in any methods of ChildClass like
That's why it worked for
So it is only accessible with the instances (
self.variable_name). If you want to access it outside the methods then you should do
For more details please check the link http://docs.python.org/reference/compound_stmts.html#class-definitions