Колонка одной таблицы может указывать на несколько таблиц в django

Допустим, у меня есть таблицы FormulaA, FormulaB...FormulaX, и productContent.

 Formula {
   characteristicsA,
   characteristicsB,
   ...
 }

Теперь каждый продукт будет основан на только одной формуле (от A до X).

Я хочу спроектировать свою базу данных таким образом, чтобы таблица productContent имела два столбца,

productContent {
  product_id, -> foreign key to product table
  formula_id -> can point to either of table formulaA,..formulaX
}

Теперь, мои заботы/требования таковы:

  1. if I have product_id, how can I get it's formula detail?

  2. Can I use select_related query here?

  3. we can take help of polymorphism, like make a common table, Formula, and from there formulaA,..formulaX can inherit. and in ProductContent table, we can have a new column, formula which will point to base table. But here also, how can I achieve requirement 1?

Вернуться на верх