我想在模板中添加一个下拉字段,并希望从我的模型中检索值。我是django的新手,所以我需要有关如何做事的帮助。
class DepartmentForm(forms.ModelForm):
department = forms.CharField(widget=forms.Select(Department.objects.all().values('department_name')))
class Department(models.Model):
department_id = models.AutoField(primary_key=True)
department_name = models.CharField("department", max_length=50)