'Django chained foreign key forms
What I am trying to do should be fairly simple.
At a high level, here is what I want:
If we have a store with multiple items, I want to categorize each item on two levels
Upper_Category:
name
Sub_Category:
name
parent -- foreign key: Upper_Category
So, each item would look like:
Item:
name
description
...etc...
category -- foreign key: Sub_Category
Filled in, they might be:
Upper_Categories:
Food
Drink
Dishes
Sub_Categories:
Meat: parent=Food
...
Beer: parent=Drink
It seems to me that I should be able to wrap this all into an editable formset based on 'Item' where each item includes a reference to what Upper_Category it belongs to
Category | Sub-Category | Name | Description
...
"Drink" | "Beer" | "Something IPA" | "beer description.."
...etc
I don't need to edit the categories and upper categories themselves, but it seems like there should be a straightforward way to reference the parent of a foreign key.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
