loading django columns dynamically from another table -


using django, want define several columns in xon model based on unique values stored in mytypes. way, not need manually define type1, type2, type3,... , can use admin page dynamically add new type column. can explain how can that?

class xon(models.model):     ge = models.charfield(max_length=200)     mu = models.charfield(max_length=200)     des = models.textfield()     type1 = models.charfield(max_length=200)     type2 = models.charfield(max_length=200)     type3 = models.charfield(max_length=200)  class mytypes(models.model):     name = models.charfield(max_length=20, primary_key=true) 

check out abstract base classes https://docs.djangoproject.com/en/1.8/topics/db/models/#abstract-base-classes

from docs:

abstract base classes

abstract base classes useful when want put common information number of other models. write base class , put abstract=true in meta class. model not used create database table. instead, when used base class other models, fields added of child class. error have fields in abstract base class same name in child (and django raise exception).

and example, docs:

from django.db import models  class commoninfo(models.model):     name = models.charfield(max_length=100)     age = models.positiveintegerfield()      class meta:         abstract = true  class student(commoninfo):     home_group = models.charfield(max_length=5) 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -