我是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的用户文章
也许这是一些更好的方式来做到这很喜欢我会知道更好的解决方案