我创建了一个网页,适用于将数据输入数据库的数据输入操作符。我用modelForm来获取数据。当我使用它时,django会引发一个错误,即“ModelForm没有指定模型类”。我该怎么办?
model.py
class Person(models.Model):
NIC = models.CharField(unique=True,max_length=12)
FName = models.CharField(max_length=30)
LName = models.CharField(max_length=30)
FullName = models.CharField(max_length=100)
DOB = models.DateField()
Nationality = models.CharField(max_length=20)
AddressLine1 = models.CharField(max_length=100)
AddressLine2 = models.CharField(max_length=100)
AddressLine3 = models.CharField(max_length=100)
AddressLine4 = models.CharField(max_length=100, null=True,blank=True)
ContactNum = models.CharField(max_length=12)
Email = models.EmailField()
FacebookProf = models.CharField(max_length=100,null=True,blank=True)
LinkedInProf = models.CharField(max_length=100,null=True,blank=True)
PImage = models.ImageField(upload_to= Person_directory_path,null=True)
Objective = models.TextField()
CVPDF = models.ImageField(upload_to=Person_directory_path)
SpecialNotes = models.TextField(blank=True,null=True)
Department = models.ManyToManyField("Department")
Post = models.ManyToManyField("Post")
Degree = models.ManyToManyField("Degree",through="Person_Degree",null=True)
Interview = models.ManyToManyField("Interview",through='Person_Interview',null=True)
def __str__(self):
return self.NIC, self.FName, self.LName, self.FullName, self.Email
forms.py
from django.forms import ModelForm
from django import forms
from .models import Person
class Interview_Form(forms.ModelForm):
class meta:
model = Person
fields = ['NIC', 'FName', 'LName','FullName','Email']
views.py
from .forms import *
def deo(request):
deoForm = Interview_Form()
context = {
'deoForm':deoForm,
}
return render(request, 'deo.html', context)
答案 0 :(得分:0)
对我而言,您似乎正在从django.forms导入ModelForm,但是当您创建Interview_form时,您正在使用forms.ModelForm。
你应该只使用ModelForm。