我对Python和Django比较陌生,请原谅我的无知。在
保存表单集时收到以下错误
IntegrityError at /jobs/1/
jobs_education.applicant_id may not be NULL
以下是我的观点:
^{pr2}$如您所见,我并不是手动设置表单集的申请人_id,但这并没有产生任何影响。在
输出:
print 'formset %s' % formset.__dict__
是
{'auto_id': u'id_%s', 'is_bound': True, 'initial_extra': None, 'error_class': <class 'django.forms.util.ErrorList'>, 'save_as_new': False, '_non_form_errors': [], 'initial': None, 'queryset': [], '_pk_field': <django.db.models.fields.AutoField: id>, 'forms': [<django.forms.models.EducationForm object at 0x1014078d0>], 'instance': <Applicant: >, 'prefix': u'education_set', 'applicant_id': 4, 'data': <QueryDict: {u'education_set-0-date': [u'1989-05-19'], u'education_set-0-school': [u'asdf'], u'education_set-0-grade': [u'oi'], u'telephone': [u'mlk'], u'nationality': [u'lk'], u'address_postcode': [u'lk'], u'address_line2': [u'lkm'], u'address_line1': [u'm'], u'education_set-MAX_NUM_FORMS': [u'1000'], u'applicant_dob': [u'1989-05-14'], u'address_district': [u'lkm'], u'csrfmiddlewaretoken': [u'3tfdnCwqYSWkyoTjEBX6peUVCGRANSKj'], u'email': [u'lkm@c.com'], u'national_insurance_number': [u'mlk'], u'address_county': [u'lkm'], u'job': [u'1'], u'address_town': [u'lkm'], u'education_set-INITIAL_FORMS': [u'0'], u'education_set-0-town': [u'sdf'], u'education_set-TOTAL_FORMS': [u'1'], u'applicant_name': [u'asd'], u'education_set-0-applicant': [u''], u'mobile': [u'm'], u'education_set-0-id': [u''], u'applicant_surname': [u'klm'], u'education_set-0-qualification': [u'oj']}>, '_errors': [{}], 'files': {}}
如果还有什么我可以提供给你的,请告诉我。在
提前谢谢你
克里斯
编辑:
在这里添加我的模型,因为有人一定会要求它们
class Location(models.Model):
location_name = models.CharField(max_length=50)
def __str__(self):
return self.location_name
class Job(models.Model):
location = models.ForeignKey(Location)
job_title = models.CharField(max_length=50)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.job_title
class Applicant(models.Model):
job = models.ForeignKey(Job)
applicant_name = models.CharField(max_length=50)
applicant_surname = models.CharField(max_length=50)
applicant_dob = models.DateField('Date of Birth')
nationality = models.CharField(max_length=50)
national_insurance_number=models.CharField(max_length=20)
address_line1=models.CharField(max_length=50)
address_line2=models.CharField(max_length=50)
address_district=models.CharField(max_length=50)
address_town=models.CharField(max_length=50)
address_county=models.CharField(max_length=50)
address_postcode=models.CharField(max_length=50)
telephone=models.CharField(max_length=12)
mobile=models.CharField(max_length=12)
email=models.EmailField(max_length=50)
approved=models.BooleanField(default=False)
def __str__(self):
return self.applicant_name
def isApproved(self):
return self.approved
def approve(self):
self.approved = True
class Education(models.Model):
applicant = models.ForeignKey(Applicant)
school=models.CharField(max_length=50)
town=models.CharField(max_length=50)
date=models.DateField('date')
qualification=models.CharField(max_length=50)
grade=models.CharField(max_length=50)
def __str__(self):
return self.school
表单集是一组表单。它没有申请者ID。尝试设置一个没有意义。在
实际上你已经在做正确的事情了。在GET块中,您正确地将
instance
参数传递给formset实例化,以将其与申请者关联。但你不能在邮政信箱里这么做,你应该:相关问题 更多 >
编程相关推荐