Answer the question
In order to leave comments, you need to log in
How to add dependent selection in Django admin?
There is a class Product Options
class Options(models.Model):
"""Опции для товара - минералы, пищевая ценность, витамины"""
TITLE_CHOICES = (
("food", "Пищевая ценность"),
("vitamins", "Витамины"),
("minerals", "Минералы"),
)
INFO_CHOICES = (
("carb", "Углеводы"),
("protein", "Белки"),
("fats", "Жиры"),
("kal", "кКал"),
)
title = models.CharField(
max_length=10, default="food", choices=TITLE_CHOICES, verbose_name="Тип опций"
)
info = models.CharField(
max_length=10, default="carb", choices=INFO_CHOICES, verbose_name="Значение опции"
)
quantity = models.PositiveSmallIntegerField(
verbose_name="Количество в товаре", default=0
)
Answer the question
In order to leave comments, you need to log in
The question has been changed, now it sounds like a friend.)
How can the Junge understand carbohydrates are vitamins or minerals.
Well, in any case, you need a separate table where there is data on dependencies.
You need to normalize your database or even revise the logic.
If you normalize the database, you will get two reference tables where you will connect energy and feces, and the third with data where you will already enter data. (Unless, of course, I understand correctly what you want at all.)
PS For me, you first need to speculate the database normally, and only then ask questions to janga) good luck.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question