我正在開發一個使用谷歌appengine和Django的Web應用程序,但我認爲我的問題更一般。用戶表的最佳數據庫設計(模型)
用戶有可能創建表,請看:表不在數據庫中表示爲TABLES。我舉一個例子:
First form: Name of the the table: __________ First column name: __________ Second column name: _________ ...
列數不固定,但有一個最大值(例如100)。每列中的類型都是相同的。
Second form (after choosing a particular table the user can fill the table): column_name1: _____________ column_name2: _____________ ....
我使用這個解決方案,但它是錯誤的:
class Table(db.Model):
name = db.StringProperty(required = True)
class Column(db.Model):
name = db.StringProperty(required = True)
number = db.IntegerProperty()
table = db.ReferenceProperty(table, collection_name="columns")
class Value(db.Model):
time = db.TimeProperty()
column = db.ReferenceProperty(Column, collection_name="values")
當我要列出一個表我把它列
,並從每列我拿自己的價值觀:
data = []
for column in data.columns:
column_data = []
for value in column.values:
column_data.append(value.time)
data.append(column_data)
data = zip(*data)
我認爲問題是值的順序,因爲其他列的順序不一定是一樣的。我正在等待這個錯誤(但直到現在我從來沒有見過它):
Table as I want: as I will got: a z c a e c d e f d h f g h i g z i
更好的解決方案?也許使用ListProperty?
這個問題不是很清楚;您需要的表格的性質與您獲得的表格的性質與您顯示的數據存儲模型有點模糊不清。另外,我不確定您是否有問題,或者只是擔心您會遇到問題。 – 2010-01-17 12:44:36
問題很簡單:用戶可以創建一個表。一個表格是用戶看作是一個表格的東西,但並不是必要的,它被作爲一個表格存儲在數據庫中。用戶選擇表中有多少列和他們的名字。用戶用數據填充表格。表中的每個條目都是相同的類型。用戶可以創建多個表。 看到這個:http://donotmissthebus.appspot。com/path /(現在表中的列固定爲兩個:開始和結束,bus *未實現)。 我認爲我的解決方案不是非常線性和容易出錯的。 – 2010-01-17 21:58:24
這種阻抗不匹配可能是關係數據庫是工作的錯誤工具的證據。你是否考慮過一個鍵值存儲,例如:「無數據庫」數據庫,還是具有API的分佈式文件系統之一? – 2010-01-27 15:16:08