django - Is not using models.*Field for variables in models allowed? -


if have model:

class model(models.model):   variable_name = value   variable_name2 = models.fieldtype(default=value) 

what's difference; first 1 allowed? kind of variable that?

i.e count = 2 vs count = models.integerfield(default=2) 

follow question

i know inherently goes against constant variables there variable shared among instances still editable?

static/constant variables seem shared among instances definition seems must defined in code; instead of user input want.

class dog(models.model): var = 10; # static variable, want changeable in admin

instance = dog(____) # var = 10

as @nightshadequeen said, models.*field fields saved database. other constant.

as second question, no there not. constant , while can change it, remain changed scope of instance. here's example of mean:

class example(models.model):   variable_name = 5  def description():     instance_a = example()     instance_a.variable_name == 5  # true     instance_a.variable_name = 'hello'     instance_a.variable_name == 'hello'  # true     instance_b = example()     instance_b.variable_name == instance_a.variable_name  # false     instance_b.variable_name == 5  # true 

the best thing create singleton model house global variables want re-used every user.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -