django choicefield在python 3.6上运行不佳

时间:2017-11-20 23:56:39

标签: django-models django-forms django-templates python-3.6 modelchoicefield

我有一个表单页面,里面有一些选择字段。在我的本地机器上使用python 3.4.3,选择字段运行良好。在python 3.6.3上,选择字段列出了选项但是; 1.选项是水平列出的 2.选择不可选。 3.选项不会显示在字段栏中。

请看下面输出显示的图片副本。 choices error output

form.py

from django import forms
from django.forms import Textarea, TextInput, Select, FileInput

class PostGraduateForm(forms.ModelForm):

    class Meta:
        model = PostGraduate
        fields = '__all__'
        exclude = ['is_visible']
        widgets = {
            'surname': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'firstname': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'middle_name': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'email_address': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'phone_number': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'contact_address': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'course': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'nationality': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'gender': Select(attrs={'style': 'height: 30px; width: 220px;'}),
            'faculty': Select(attrs={'style': 'height: 30px; width: 220px;'}),
            'form_number': TextInput(attrs={'size': '27', 'style': 'height: 30px;', 'placeholder': '  E.g. PGXXXXXXXXX'}),
            'department': Select(attrs={'style': 'height: 30px; width: 220px;'}),
            'programme': Select(attrs={'style': 'height: 30px; width: 220px;'}),
            'academic_session': TextInput(attrs={'size': '27', 'style': 'height: 30px;'}),
            'passport': FileInput(attrs={'style': 'height: 30px; width: 220px;'}),
            'project_proposal': FileInput(attrs={'style': 'height: 30px; width: 220px;'}),
            'project_title': Textarea(attrs={'cols': 75, 'rows': 20, 'style': 'height: 110px;'}),                   
        }

model.html

class PostGraduate(models.Model):
    surname = models.CharField(max_length = 50)
    firstname = models.CharField(max_length = 50)
    middle_name = models.CharField(max_length = 50, blank = True)
    pg_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    email_address = models.EmailField(unique = True, max_length = 50)
    phone_number = models.CharField(max_length = 15)
    identification = models.CharField(max_length=100, blank=True, unique=True, default=uuid.uuid4().hex[:6].upper(), editable=False)

    FEMALE = 'FEMALE'
    MALE = 'MALE'
    GENDER_CHOICES = ((MALE, 'MALE'), (FEMALE, 'FEMALE'))
    gender = models.CharField(max_length = 10, choices=GENDER_CHOICES, default=None)
    #password = models.CharField(max_length = 50)
    nationality = models.CharField(max_length = 50)

    PHARMACEUTICAL_SCIENCES = 'PHARMACEUTICAL SCIENCES'
    NATURAL_SCIENCE = 'NATURAL SCIENCE'
    MEDICAL_LABOURATORY = 'MEDICAL LABOURATORY'
    FACULTY_CHOICES = ((PHARMACEUTICAL_SCIENCES, 'PHARMACEUTICAL SCIENCES'), (NATURAL_SCIENCE, 'NATURAL SCIENCE'), (MEDICAL_LABOURATORY, 'MEDICAL LABOURATORY'))
    faculty = models.CharField(max_length = 50, choices=FACULTY_CHOICES, default=None)
    form_number = models.CharField(unique = True, max_length = 50)

    PHARMACEUTICAL_CHEMISTRY = 'PHARMACEUTICAL CHEMISTRY'
    CLINICAL_PHARMACY = 'CLINICAL PHARMACY'
    PHARMACOGNOSY = 'PHARMACOGNOSY'
    PHARMACEUTICAL_TECHNOLOGY = 'PHARMACEUTICAL TECHNOLOGY'
    PLANT_SCIENCE = 'PLANT SCIENCE AND TECHNOLOGY'
    CHEMISTRY = 'CHEMISTRY'
    BIOCHEMISTRY = 'BIOCHEMISTRY'
    DEPARTMENT_CHOICES = (
        (PHARMACEUTICAL_CHEMISTRY, 'PHARMACEUTICAL CHEMISTRY'), (CLINICAL_PHARMACY, 'CLINICAL PHARMACY'), 
        (PHARMACOGNOSY, 'PHARMACOGNOSY'), (PHARMACEUTICAL_TECHNOLOGY, 'PHARMACEUTICAL TECHNOLOGY'),
        (PLANT_SCIENCE, 'PLANT SCIENCE AND TECHNOLOGY'), (CHEMISTRY, 'CHEMISTRY'), (BIOCHEMISTRY, 'BIOCHEMISTRY')
    )
    department = models.CharField(max_length = 500, choices=DEPARTMENT_CHOICES, default=None)

    MSc = 'MASTERS (MSc)'
    PhD = 'DOCTOR OF PHILOSOPHY (PhD)'
    PROGRAMME_CHOICES = ((MSc, 'MASTERS (MSc)'), (PhD, 'DOCTOR OF PHILOSOPHY (PhD)'))
    programme = models.CharField(max_length = 500, choices=PROGRAMME_CHOICES, default=None)
    academic_session = models.CharField(max_length = 500)
    contact_address = models.CharField(max_length = 500)
    course = models.CharField(max_length = 500)
    project_title = models.TextField(blank = False)
    project_proposal = models.FileField(upload_to='Post Graduate/proposal/%d-%m-%Y/', blank = False,)
    passport = models.ImageField(upload_to='Post Graduate/passport/%d-%m-%Y/', blank = False,)
    created_at = models.DateTimeField(auto_now_add = True)
    updated_at = models.DateTimeField(auto_now = True)
    is_visible = models.BooleanField(default = False)

    def get_absolute_url(self):
        return reverse('peruse:post_detail', kwargs={'pk': self.pg_id})

    def __str__(self):
        return self.surname + ' - ' + self.firstname

    def id(self):
        return self.id

0 个答案:

没有答案