2

Scenario

A well-known taco establishment wants to build a Django app with models Combo, ComboItem, Ingredient, and Order.

  1. Headquarters wants to create various combos with included items and layout the original item ingredients and price.
  2. Each franchise can then select which combos they will sell on their menu and is allowed to adjust the price and ingredients of combo items for their store.
  3. When an order comes in, the combo and item details should show on a log and should not change in the future if HQ renames a combo or the franchise changes the price/ingredients.

Use Case

  1. HQ creates the "Hot Taco Combo". It has three 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 the Hot Taco Combo to their menu. They adjust the price of the taco to $1.49 and add lettuce to the taco.

  3. A customer orders the combo with no cheese on the taco.

  4. HQ changes the name of the combo to Fiery Taco Combo - NY's combo name updates but the taco remains the same custom price and still includes lettuce.

  5. A manager at the NY franchise views all orders and see's one order for Hot Taco Combo and the taco ingredients are only shell, meat, and lettuce.

Issue

I'm struggling to decide the best way to handle this because a Combo is basically the same object at all three levels, but its related ComboItem objects can be different. HQ should be able to update Combo attributes like the name and it would update all franchise combo names, but the combo item customizations should remain. Additionally, combo details and customizations at the point of sale should never change once recorded, for accurate order records.

Originally I thought to have an AbstractBaseClass for each of the related models and objects that inherit from them at each business level, but that structure feels redundant and difficult to maintain.

Then I thought to use GenericForeignKey to relate the Combo to either HQ, Franchise, or an Order and duplicate objects where necessary as they move down the levels. This feels weird and error prone.

Has anyone dealt with a case like this or have any recommendations? Is it just a matter of being a complex problem and needing a complex solution or is there a simple approach I'm missing? Thank you in advance.

Ryan Allen
  • 5,414
  • 4
  • 26
  • 33

1 Answers1

1

It sounds like rather than abstract base classes, you're looking to use multi-table inheritance: https://docs.djangoproject.com/en/1.8/topics/db/models/#multi-table-inheritance

I'd recommend reading through this whole section of the docs to see what your options are for inheritance styles: https://docs.djangoproject.com/en/1.8/topics/db/models/#model-inheritance

Bradford Wade
  • 495
  • 1
  • 4
  • 10