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.

  1. headquarters wants create various combos included items , layout original item ingredients , price.
  2. each franchise can select combos sell on menu , allowed adjust price , ingredients of combo items store.
  3. 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

  1. 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)
  2. the ny franchise adds hot taco combo menu. adjust price of taco $1.49 , add lettuce taco.

  3. a customer orders combo no cheese on taco.

  4. hq changes name of combo fiery taco combo - ny's combo name updates taco remains same custom price , still includes lettuce.

  5. 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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -