如何将模型值添加到下拉字段

时间:2019-05-03 19:25:02

标签: django django-models

我想在模板中添加一个下拉字段,并希望从我的模型中检索值。我是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)

0 个答案:

没有答案