在.xls中导出django模型

时间:2016-09-29 15:06:55

标签: django excel python-2.7

如何将填充了数据(大约15列和2500行)的整个模型导出到excel文件中,以便通过html页面中的按钮直接下载?

这是我的模特:

class Cleartobill(models.Model):
    soss = models.CharField(max_length=60)
    soss_line = models.CharField(max_length=70)
    build_date = models.CharField(max_length=80)
    ctb_Status = models.CharField(max_length=60)
    ctb_comment = models.CharField(max_length=50)
    comments = models.CharField(max_length=200)
    sjz_status = models.CharField(max_length=60)
    production_result_Code = models.CharField(max_length=70)
    bu = models.CharField(max_length=50)
    pf = models.CharField(max_length=50)
    current_fcd = models.DateField(null=True, blank=True)
    tan = models.CharField(max_length=50)
    eta = models.CharField(max_length=60, null=True, blank=True)
    tied = models.CharField(max_length=30)
    otm_status = models.CharField(max_length=30)
    bucket_aged = models.CharField(max_length=60)
    ead = models.DateField(null=True, blank=True)

1 个答案:

答案 0 :(得分:0)

您可以通过django serializers将模型对象序列化为json,然后通过tablib

等工具从中创建excel文件