Django不生成多个下拉列表

时间:2017-06-12 16:20:50

标签: django django-models django-forms

我正在尝试为模型添加多个下拉列表,但Django没有生成多个下拉列表.. 这是model.py文件。下拉显示为'资格'现场,但部门'没有以表格形式显示.. 这是模板文件。

<table style="width:100%">
        {% for field in form %}

          <tr>
            <td>{{ field.label_tag }}</td>
            <td>{{ field }}</td>
          </tr>

    {% endfor %}
    </table>

这里是forms.py

class EmployeeForm(forms.ModelForm):
    class Meta:
        model = Employee
        fields = ['regno','fname','lname','ffname','flname','qualification', 'num', 'email','city','contact','alternatecontact','fathercontact','joiningdate','qualification', 'department', 'experience','lastemployer','picture','isteaching','dob','status','address']

model.py

class StaffEducation(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    title = models.CharField(db_column='title', max_length=100)
    def __str__(self):
        return self.title

class Department(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    title = models.CharField(db_column='title', max_length=100)
    def __str__(self):
        return self.title

class Employee(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    regno = models.CharField(db_column='regno', max_length=100)
    fname = models.CharField(db_column='fname', max_length=100, blank=False, null=False)
    lname = models.CharField(db_column='lname', max_length=100, blank=False, null=False)
    ffname = models.CharField(db_column='ffname', max_length=100, blank=False, null=False)
    flname = models.CharField(db_column='flname', max_length=100, blank=False, null=False)
    qualification = models.ForeignKey(StaffEducation)
    num = models.DecimalField(db_column='num', default='0', decimal_places=2, max_digits=11)
    email = models.EmailField(db_column='email', max_length=100)
    address = models.TextField(db_column='address')
    city = models.CharField(db_column='city', max_length=100)
    contact = models.CharField(db_column='contact', max_length=100)
    alternatecontact = models.CharField(db_column='alternatecontact', max_length=100)
    fathercontact = models.CharField(db_column='fathercontact', max_length=100)
    joiningdate = models.DateField(db_column='joiningdate')
    department = models.ForeignKey(Department)
    #qualification = models.CharField(db_column='qualification', max_length=100)
    experience = models.CharField(db_column='experience', max_length=100)
    lastemployer = models.CharField(db_column='lastemployer', max_length=100)
    picture = models.ImageField(db_column='picture')
    isteaching = models.BooleanField()
    dob = models.DateField(db_column='dob')
    status = models.BooleanField(db_column='status')

0 个答案:

没有答案