Something I'm confused about in Django is how the model's fields work.
You define them as class variables.
So, a class like this:
avar = "something here"
f1 = Foo()
f2 = Foo()
amodel = AModel.objects.get(*)
A regular class variable is a property of the class. It is not stored in the database (only model fields are). In your case,
avar is not a model field. It is just a simple python class variable.
If you change the class variable on an instance of
Foo, it will only affect that instance. All other instances will not be affected. Proof:
class Foo: avar = 'Something' a = Foo() b = Foo() a.avar = 'Something else' print a.avar > 'Something else' print b.avar > 'Something'
Note that changing
a does not alter it on
b. Note also that the changed value of
a.avar will only exist as long as
a itself exists. This property is not stored in the database and if you load a new object from the database it will just have the default
avar of the class.