1👍
✅
I still haven’t really understood your question but this might help you.
In your models.py
course_name = ('English', 'Maths',)
from model_utils import Choices
class Course(models.Model):
course_document = models.ForeignKey(Document,null=True,blank=True)
name = models.CharField(max_length=255, choices=Choices(*course_name))
subject = models.CharField(max_length = 255)
This will create a drop down menu for choosing courses.
👤abhi
0👍
choices
should be a CharField
, with a choices argument. The value of the choices argument is a tuple
with 2 items in it. The first is a value for you to access if you need it. The second value is what the User sees. So”
class MyForm(forms.Form):
courses = forms.CharField(max_length=255, choices=(
('1', 'First Course'),
('2', 'Second Course')
)
)
Here is the Django Docs for this:
https://docs.djangoproject.com/en/dev/ref/models/fields/#choices
Source:stackexchange.com