Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database : best way to model a spreadsheet

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

  • 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.

I am thinking about something like :

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()

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.

like image 837
Guido Avatar asked Dec 31 '22 08:12

Guido


1 Answers

from a relational viewpoint:

Spreadsheet <-->> Cell : RowId, ColumnId, ValueType, Contents

there is no requirement for row and column to be entities, but you can if you like

like image 175
Steven A. Lowe Avatar answered Jan 13 '23 13:01

Steven A. Lowe