python - Model redundant django tables? -


i working figure out model django project: app track books.

among other fields, every book has either/both printer , publisher, identical. so, here's how stands:

class book(models.model):     title     = models.charfield(max_length=100)     printer   = models.foreignkey('printer')     publisher = models.foreignkey('publisher')  class printer(models.model):     name      = models.charfield(max_length=100)     location  = models.charfield(max_length=100)  class publisher(models.model):     name      = models.charfield(max_length=100)     location  = models.charfield(max_length=100) 

it seems me bad database form: it's not dry. in addition, quite often, book might printed firm publishes same or book: in other words, tables can overlap. so, 2 models printer , publisher should combined, while need remain distinct in admin.

my question: how best this? should create model, firm, , create one-to-one relationships between , printer/publisher?

the django way handle create abstract base model. dry way create models. here code:

class basemodel(models.model):     name      = models.charfield(max_length=100)     location  = models.charfield(max_length=100)      class meta:         abstract = true  class printer(basemodel):     pass  class publisher(basemodel):     pass 

this allow specify redundant fields once. also, if need add fields 1 model, add them instead of using pass.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -