django - Database structure to handle similar/same object at varying business levels -
scenario
a well-known taco establishment wants build django app models combo
, comboitem
, ingredient
, , order
.
- headquarters wants create various combos included items , layout original item ingredients , price.
- each franchise can select combos sell on menu , allowed adjust price , ingredients of combo items store.
- when order comes in, combo , item details should show on log , should not change in future if hq renames combo or franchise changes price/ingredients.
use case
hq creates "hot taco combo". has 3 related combo items
- a taco (price: $.99, ingredients: shell, beef, cheese, hot sauce)
- churro-spirals (price: $.79)
- drink (price: $1.29)
the ny franchise adds hot taco combo menu. adjust price of taco $1.49 , add lettuce taco.
a customer orders combo no cheese on taco.
hq changes name of combo fiery taco combo - ny's combo name updates taco remains same custom price , still includes lettuce.
a manager @ ny franchise views orders , see's 1 order hot taco combo , taco ingredients shell, meat, , lettuce.
issue
i'm struggling decide best way handle because combo
same object @ 3 levels, related comboitem
objects can different. hq should able update combo attributes name , update franchise combo names, combo item customizations should remain. additionally, combo details , customizations @ point of sale should never change once recorded, accurate order records.
originally thought have abstractbaseclass
each of related models , objects inherit them @ each business level, structure feels redundant , difficult maintain.
then thought use genericforeignkey
relate combo either hq, franchise, or order , duplicate objects necessary move down levels. feels weird , error prone.
has dealt case or have recommendations? matter of being complex problem , needing complex solution or there simple approach i'm missing? thank in advance.
it sounds rather abstract base classes, you're looking use multi-table inheritance: https://docs.djangoproject.com/en/1.8/topics/db/models/#multi-table-inheritance
i'd recommend reading through whole section of docs see options inheritance styles: https://docs.djangoproject.com/en/1.8/topics/db/models/#model-inheritance
Comments
Post a Comment