I am trying to make a web app that allows users to create "virtual tables" each with its own rows, columns and data. Each user will be able to CRUD their own virtual tables (using an API I am trying to build with django-rest-framework), but they should not be able to see other users' tables.
我正在尝试开发一个web应用程序,允许用户创建“虚拟表”,每个表都有自己的行、列和数据。每个用户都可以CRUD自己的虚拟表(使用我正在尝试使用django rest-framework构建的API),但是他们不应该能够看到其他用户的表。
So far, my first attempt at a model looks like this:
到目前为止,我对模型的第一次尝试是这样的:
class Vtable(models.Model):
user = models.ForeignKey(User)
table_name = models.CharField(max_length=200)
class Vcolumn(models.Model):
table = models.ForeignKey(Vtable)
column_name = models.CharField(max_length=200)
class Vrow(models.Model):
table = models.ForeignKey(Vtable)
added_date = models.DateTimeField('date added')
class Vdata(models.Model):
table = models.ForeignKey(Vtable)
row = models.ForeignKey(Vrow)
column = models.ForeignKey(Vcolumn)
data = models.CharField(max_length=200)
I just went through the tutorial for the django-rest-framework, and now I am not sure if it makes sense to normalize everything. Would it be better to have one big table instead? I imagine that it would be very very annoying to implement serialization as well as when permissions come into the mix. I am VERY new to Django, I am looking for some guidance.
我刚刚浏览了django rest-framework的教程,现在我不确定将所有内容规范化是否有意义。换一张大桌子好吗?我认为,实现序列化以及权限混合时都是非常烦人的。我是Django的新手,我在寻找一些指导。
Thanks in advance!
提前谢谢!
1 个解决方案
#1
1
For this sort of thing you might want to consider storing each set of table data in a JSON field rather than trying to coerce database tables into a style they're not well suited too.
对于这种类型的东西,您可能需要考虑将每组表数据存储在JSON字段中,而不是试图将数据库表强制为它们不太适合的样式。
Using a plain JSON field for the table storage may or may not be suitable depending on what kind of lookups (if any) you'll need to perform inside tables, and how much data they'll contain, but it'd certainly be easier to work with.
在表存储中使用纯JSON字段可能适合,也可能不适合,这取决于需要在表内部执行何种查找(如果有的话),以及它们将包含多少数据,但使用它肯定更容易。
You could still enforce constraints on the data in the table cells using REST framework's serializers or something similar to that, if you need to ensure that certain cells are of a particular data type.
如果您需要确保某些单元格属于特定的数据类型,您仍然可以使用REST框架的序列化器或类似的东西对表单元格中的数据实施约束。
#1
1
For this sort of thing you might want to consider storing each set of table data in a JSON field rather than trying to coerce database tables into a style they're not well suited too.
对于这种类型的东西,您可能需要考虑将每组表数据存储在JSON字段中,而不是试图将数据库表强制为它们不太适合的样式。
Using a plain JSON field for the table storage may or may not be suitable depending on what kind of lookups (if any) you'll need to perform inside tables, and how much data they'll contain, but it'd certainly be easier to work with.
在表存储中使用纯JSON字段可能适合,也可能不适合,这取决于需要在表内部执行何种查找(如果有的话),以及它们将包含多少数据,但使用它肯定更容易。
You could still enforce constraints on the data in the table cells using REST framework's serializers or something similar to that, if you need to ensure that certain cells are of a particular data type.
如果您需要确保某些单元格属于特定的数据类型,您仍然可以使用REST框架的序列化器或类似的东西对表单元格中的数据实施约束。