Reputation: 25
I think I have written the correct code. But this gender radio button is not appearing in my form.
This is my model view.
class Charter(models.Model):
CHOICES = [('M', 'Male'), ('F', 'Female'), ('O', 'Others')]
Gender = forms.ChoiceField(label='Gender', widget=
forms.RadioSelect(choices=CHOICES))
created_at = models.DateField()
First_name = models.CharField(max_length=200, unique=True)
Last_name = models.CharField(max_length=200, unique=True)
address = models.CharField(max_length=200, unique=True)
Cell_no = models.CharField(max_length=200, unique=True)
created_at = models.DateField()
This is my forms.py
from django.forms import ModelForm from .models import *
class CharterForm(ModelForm):
class Meta:
model= Charter
fields = '__all__'
widgets = {
'Gender': forms.RadioSelect()
}
Upvotes: 0
Views: 344
Reputation: 21
Check out this similar link: Dropdown in Django Model
or
Refer to Django official documentation for more info
CHOICES = (
('M', 'Male'),
('F', 'Female'),
('O', 'Others'),
)
Upvotes: 1