Questions tagged «inline-formset»

3
Django-CreateView不保存带有嵌套表单集的表单
我正在尝试采用一种使用Django-Crispy-Forms布局功能将嵌套表单集与主表单保存在一起的方法,但是我无法保存它。我正在跟踪此代码示例项目,但无法验证表单集以保存数据。如果有人能指出我的错误,我将非常感激。我还需要在同一视图中为EmployeeForm添加三个内联。我尝试了Django-Extra-Views,但无法正常工作。如果您建议为同一视图(如5左右)添加多个内联,将不胜感激。我想实现的唯一目的是创建一个页面Employee及其内联Education, Experience, Others。下面是代码: 楷模: class Employee(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='employees', null=True, blank=True) about = models.TextField() street = models.CharField(max_length=200) city = models.CharField(max_length=200) country = models.CharField(max_length=200) cell_phone = models.PositiveIntegerField() landline = models.PositiveIntegerField() def __str__(self): return '{} {}'.format(self.id, self.user) def get_absolute_url(self): return reverse('bars:create', kwargs={'pk':self.pk}) class Education(models.Model): employee = models.ForeignKey('Employee', on_delete=models.CASCADE, related_name='education') course_title …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.