How to set your autoincrement primary key in AppEngine/Python?

0 like 0 dislike
9 views
There are, for example, class articles, copies of which are kept in Google release date storage. And I want to give a link to it:

[ a href="/article/{{ article.uid }}" ]

To make like this:

[ a href="/article/55" ]

Google has its UUID's, but they are a bit too scary for to be part of the url: ahBzb3ZpZXRncm9vdmVibG9ncg0LEgdBcnrpy2xlgagm.
by | 9 views

2 Answers

0 like 0 dislike
This has already been implemented. In addition to BigTable distributes keys and a numeric id. DB query by id:
\rModel.get_by_id()
To get the id of any entity — entity.key().id()
\r
It is quite suitable for a url, only to note that id will incremented for entities of any type in your application. One at all. Therefore, the numbers are big. For example, www.arhimir.ru/news/1126006 — done on GAE-Python.
by
0 like 0 dislike
probably have to use additional model:
\r
\r
class Sequence(db.Model): Key: db.StringProperty() #key, for example "ArticleId" Number: db.IntegerProperty(default=1) #the value itself 

and the meaning is — that in one transaction, first get the Number value and then update it by +1
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
1,107 users