Reputation: 2292
I am creating a model with fields that will provide choices for the user so I am using keyword choices
like this:
ACQUIRED_FROM=(
('dealer', 'Dealer'),
('private', 'Private'),
('show', 'Show'),
('family member', 'Family Member'),
('other', 'Other'),),
and specifying the field like this:
acquired_from = models.CharField(max_length=100, choices=ACQUIRED_FROM)
Under family member I need the user to input the specific person (e.g. father, uncle, e.t.c).
I think it will also apply to a currency field that will enable the user to choose whether the input is in dollars or euros and then specifying the amount.
The question is how can I define the choices to enable user input?
This is a simpler way to ask the same question above:
LENGTH=(
('CENTIMETERS', 'cm'),
('INCHES', 'in'),),
With this I would like the user to select either inches or centimeters and then input the actual value. How should I modify it?
Upvotes: 3
Views: 699
Reputation: 6834
Django choices
is not meant for dynamic content.
If your intention is to build nested choices
(aka group choices
), you can pre-define the list of choices for family member
the same as you defined it for acquired_from
.
ACQUIRED_FROM = (
('dealer', 'Dealer'),
('private', 'Private'),
('show', 'Show'),
('Family Member', (
('father', 'Father'),
('uncle', 'Uncle'),
)
),
('other', 'Other'),
)
Upvotes: 1