如何获取模型formset以保存正确的人?

时间:2014-09-15 18:31:14

标签: django django-models django-forms

我有一些基于数据库中人员的表单。基本上在任何给定时间,用户可以提供约3人来判断。人们基于现有的数据库实例,他们的分数通过主键与它们相关联。我试图让这些表格集为每个人保存。

型号:

class couples(model.Model):

     dancer_fname = models.CharField('Dancer 1 First Name', max_length = 30)
     dancer_lname = models.CharField('Dancer 1 Last Name', max_length = 30)
     number = models.CharField('Number', max_length = 5)  


 class score(models.Model):

     couple_r1 = models.ForeignKey(couples, null=True, blank=True,  )
     number = models.CharField('Number', max_length = 5)

     judge = models.CharField(max_length = 50)

     style = models.FloatField(max_length = 10, null=True, blank=True )
     time = models.FloatField(max_length = 10, null=True, blank=True)

查看:

    couplelist = couple.objects.all()

    FormSet = modelformset_factory(score, form = heatform)
    form = FormSet(queryset = score.objects.none())

模板:

   {% for X in couplelist %}
   {{form}}
   <input type = "hidden" value="X.number" name="number">
   <input type = "hidden" value="X.pk" name="pk">

   {% endfor %}

如何保存以便每位参赛者获得他们的分数,并在正确的行上编号。

0 个答案:

没有答案