本文介绍了数据库:建立电子表格的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图找出建立电子数据表的最佳方式(从数据库的角度),考虑到:

I am trying to figure out the best way to model a spreadsheet (from the database point of view), taking into account :


  • 电子表格可以包含可变数量的行。

  • 电子表格可以包含可变数量的列。

  • 每列可以包含一个单一值,但其类型未知(整数,日期,字符串)。

  • 生成包含数据的CSV文件必须很简单(和执行)。

  • The spreadsheet can contain a variable number of rows.
  • The spreadsheet can contain a variable number of columns.
  • Each column can contain one single value, but its type is unknown (integer, date, string).
  • It has to be easy (and performant) to generate a CSV file containing the data.

我正在考虑如下:

class Cell(models.Model):
    column = models.ForeignKey(Column)
    row_number = models.IntegerField()    
    value = models.CharField(max_length=100)

class Column(models.Model):
    spreadsheet = models.ForeignKey(Spreadsheet)
    name = models.CharField(max_length=100)
    type = models.CharField(max_length=100)

class Spreadsheet(models.Model):
    name = models.CharField(max_length=100)
    creation_date = models.DateField()

我的方法允许以String形式存储数据。我担心生成CSV文件太慢了。

Can you think about a better way to model a spreadsheet ? My approach allows to store the data as a String. I am worried about it being too slow to generate the CSV file.

推荐答案

你可能想学习EAV(Entity-attribute-价值)数据模型,因为他们试图解决类似的问题。

You may want to study EAV (Entity-attribute-value) data models, as they are trying to solve a similar problem.

这篇关于数据库:建立电子表格的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:27