python - Django models with same or similar fields -


i started learn django , have 1 question: kind of model creation better if tables have similar fields? 1) standart way form official tutorial like

class place(models.model):     name = models.charfield(max_length=50)     address = models.charfield(max_length=80)  class restaurant(models.model):     name = models.charfield(max_length=50)     address = models.charfield(max_length=80)     serves_hot_dogs = models.booleanfield()     serves_pizza = models.booleanfield() 

as see both models have same name , address fields. found in https://docs.djangoproject.com/en/1.6/topics/db/models/#multi-table-inheritance multi-table ingeritance works this: 2)

class place(models.model):     name = models.charfield(max_length=50)     address = models.charfield(max_length=80)  class restaurant(place):     serves_hot_dogs = models.booleanfield()     serves_pizza = models.booleanfield() 

as doc says: of fields of place available in restaurant, although data reside in different database table.

well, there principal differences beteeen two? , 1 shall use?

in case, think should use inheritance (solution 2).

because restaurant special place, means restaurant have field name , address, additionally, restaurant have field serves_hot_dogs , serves_pizza.

considering above description, solution reasonable. but, restaurant place, restaurant must can processed place. in solution1, restaurant , place separated, cannot process restaurant place.(just considering oop)

in other side, in solution1, if save place address a, , add restaurant same address. save same address twice in database, leads redundant , inconsistency.


this question similar different of composition , inheritance in oop.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -