I want to display the choice field in forms.
This is my model but I am not able to see the select box, it displays as textarea.
SOURCE_CHOICES = Choices(
('var1', '1'),
('var2', '2')
)
source = models.TextField(choices=SOURCE_CHOICES, null=True, blank=True)
Do I need to put something in my form as well?
In my previous project I did the same thing. I defined everything in my model and saw the select box but not here.
You should use CharField
instead TextField
:
source = models.CharField(choices=SOURCE_CHOICES, max_length=3, ... )
TextField is rendered always as TextArea.
https://docs.djangoproject.com/en/dev/ref/models/fields/#choices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With