我是GAE中的新成員,所以如果您想幫忙,請寫下一些詳細信息和示例。在Google應用程序引擎中設計數據庫
我想要做兩個db模型,用戶和文章。每個用戶可以有一些文章。在SQL Server中這將是:
create table User
(
id int primary key identity(1,1),
login nvarchar(50) unique not null,
password nvarchar(50) not null,
email nvarchar(50) unique not null,
)
create table Article
(
userId int references User(id) not null,
topic nvarchar(50) not null,
content nvarchar(max) not null
)
在Python中我嘗試:
class Article(db.Model):
topic = db.StringProperty(multiline=False)
content = db.StringProperty(multiline=True)
class User(db.Model):
login = db.StringProperty()
email = db.EmailProperty()
password = db.StringProperty(multiline=False)
articles = db.ListProperty(int) #here I want to do db.ListProperty(Article), but I can't. So I want to keep here id of article.
而且我的問題是:
- 我怎麼能提供登錄和電子郵件將是獨一無二的
我如何獲得用戶的主鍵(在sql
select id from User where login = 'sada' and password = 'sd'
- 我如何使用這個主鍵搜索用戶
- 我怎麼能增加對用戶新的文章,如果我想保持ID的用戶文章
也許這是一些更好的方式來做到這很喜歡我會知道更好的解決方案