为什么我的数据库条目会变空?

时间:2014-06-20 04:13:44

标签: django django-models django-forms

我尝试根据下面的表单创建新实例,但是当它保存时,数据库只保存外键值和订单值,但没有别的。任何想法为什么?

模型:

class danceType(models.Model):
    eventtype = models.ForeignKey(compType)
    dance_name = models.CharField(max_length = 20)
    Price = models.FloatField(max_length = 7, null=True, blank=True )
    field_2 = models.CharField(max_length = 20, null=True, blank=True)
    def __unicode__(self):
      fields = ('field_2')
      return self.dance_name 


class dancer(models.Model):
    dancetype = models.ForeignKey(danceType)
    e_number = models.IntegerField(max_length = 4, null=True, blank=True)
    D1_first_name = models.CharField(max_length = 20)
    D1_last_name = models.CharField(max_length = 20)
    D1_email = models.EmailField(max_length = 20)
    city = models.CharField(max_length = 20)
    order = models.PositiveIntegerField()
    perform = models.NullBooleanField(null=True, blank=True)

查看:

if request.method =='POST':

    sub_type = request.POST.get("form")
    dancetype = request.POST.get("dancetype")
    ext = request.POST.get("quantity")

    form = modelformset_factory(dancer, form=CompReg, extra=int(ext))
    productform = form(queryset = dancer.objects.none())

    if sub_type == "submitted":

        productform = form(request.POST, request.FILES)

        if productform.is_valid():
            for p in productform:
                dance=p.save(commit=False)
                dance.dancetype_id = 4
                dance.order = 1
                dance.save()
        else:
            der = "it didnt save"

0 个答案:

没有答案