Django: parametrizing db_table for inheritance -


i want set db_table meta class attribute in base class inherited classes have names in it, similar how django treats related_name model field attribute:

class basemodel(models.model):     class meta:         db_table = 'prefix_%(class)s' 

so inherited model:

class submodel(basemodel):     pass 

will have db table prefix_submodel.

is possible? can meta class access inheriting class' model name?

no. can't that. not simple have same table store multiple classes.

what need djeneralize project.

from examples:

class fruit(basegeneralizedmodel):    name = models.charfield(max_length=30)     def __unicode__(self):        return self.name  class apple(fruit):    radius = models.integerfield()     class meta:        specialization = 'apple'  class banana(fruit):    curvature = models.decimalfield(max_digits=3, decimal_places=2)     class meta:        specialization = 'banana'  class clementine(fruit):    pips = models.booleanfield(default=true)     class meta:        specialization = 'clementine'  allows following queries executed:  >>> fruit.objects.all() # we've got @ moment [<fruit: rosy apple>, <fruit: bendy banana>, <fruit: sweet clementine>] >>> fruit.specializations.all() # new stuff! [<apple: rosy apple>, <banana: bendy banana>, <clementine: sweet clementine>] 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -