I new in GAE, so if you want to help, please write some details and example.
I’m trying to do two db models, User and Article. Each user can have some article. In sql server it would be:
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
)
In python I try:
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.
And my questions are:
- how can I provide that login and email will be unique
-
how can I get primary key for User (in sql
select id from User where login = 'sada' and password = 'sd' - how can I use this primary key to search user
- how can I add new article for User, if I want to keep id in User-articles
Maybe it is some better way to do this, gladly I will know a better solution
First the Google AppEngine Datastore is not a relational database. This is a completely different paradigm. Maybe you should first have a look at the Datastore Overview documentation or Mastering the datastore.
Regarding your specific questions:
user = db.GqlQuery("SELECT * FROM Users WHERE login IS :1", login)