python - Use main class' properties in subclass? -


sample:

from django.db import models   class basemodel(models.model):     choices = ((0, 'nope'),                (1, 'yep'),)     # ...   class p(basemodel):     p = models.smallintegerfield(default=1, choices=basemodel.choices) 

it's unnecessary inherit basemodel if use basemodel.choices.but must inherit because other column.

how let p inherit choices property instead of using it's father's choices?

in example p not inherited field, cannot "inherit" basemodel. p (the subclass) will inherit choices basemodel @ point field p defined p class doesn't yet exists (it exists after end of class statement body), cannot reference p.choices @ point, , since name choices not defined in p class statement's body, cannot reference either. snippet plain simple , obvious solution.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -