如何在POST请求中获取Django表值

时间:2019-03-18 13:22:51

标签: django-views

我有以下模型:

lastrow = Cells(Rows.Count, "C").End(xlUp).Row + 1
Cells(lastrow + 1, 3).Formula = "=sum(C1:C" & lastrow & ")"
lastrow = Cells(Rows.Count, "D").End(xlUp).Row + 1
Cells(lastrow + 1, 4).Formula = "=sum(D1:D" & lastrow & ")"

我使用Django表在列上添加操作:

class Sccinfo(models.Model):
    primary_key = models.IntegerField(primary_key=True)
    chip_kind = models.CharField(max_length=20, blank=True, null=True)
    project_code = models.ForeignKey(Projects, models.DO_NOTHING, db_column='project_code')
    board_type = models.CharField(max_length=9)
    period = models.CharField(max_length=5)
    scc_image = models.CharField(max_length=8, blank=True, null=True)
    scc_platform = models.ForeignKey(Platforms, models.DO_NOTHING, db_column='scc_platform')
    minor = models.CharField(max_length=4, blank=True, null=True)
    label = models.CharField(max_length=15)
    atr = models.CharField(db_column='ATR', max_length=66)  # Field name made lowercase.
    scc_interface = models.CharField(max_length=15, blank=True, null=True)
    anti_reqiuered = models.IntegerField()
    lockable = models.IntegerField()
    mse_file = models.CharField(max_length=15, blank=True, null=True)
    notes = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
    db_table = 'sccinfo'

观看次数:

class SccinfoTable(tables.Table):
    scc_platform=tables.Column(attrs={'td': {"contenteditable": "false"}})
    selection = tables.CheckBoxColumn(accessor='pk', orderable=False)

    def render_board_type(self, value):
        return get_template_values(GEN,value)
    def render_project_code(self,value):
        return get_template_values(Projects.objects.all(),value)

    class Meta:
        model = Sccinfo
        template_name = "django_tables2/bootstrap-responsive.html"
        # exclude = ('id',)
        # order_with_respect_to = 'project_name'
        attrs = { 'style':'max-width:100%; white-space:nowrap;','td': {"contenteditable" : "true"},'th':{'style':'width:auto !important'}}
        sequence = ('selection','...')

HTML:

class SccInfoView (SingleTableView):
    model = Sccinfo
    template_name = "sccinfo.html"

def get(self, request, *args, **kwargs):
    # self.data_info=Sccinfo.objects.all()
    table = SccinfoTable(Sccinfo.objects.all())       
    return render(request,self.template_name, {'table': table})

 def post(self, request, *args, **kwargs):
    table = SccinfoTable(request.POST)
    # for row in table.rows://???

我希望能够获得该表(在请求后)并将选定的行保存到数据库中。我试图从表中获取Queryset对象,或者至少获取了单元格值,但无法检索它们。我该怎么办?

谢谢!

0 个答案:

没有答案