Django's model has "id" field. It is auto-increment, unique integer for each models. GAE Datastore also has "id" field. It is *not* auto-increment, unique integer for *all* models. And you can not set the field as you want. This is annoying.
If you use Django's "id" field in permalink etc. (as I did), you need to add some field like "oldid", move old "id" value in it and write some code to put such a value in new coming items. For your information, when you can't inherit User models, you need to make a wrapper model. And also, you should change all code searching items with "id". You should change all "get_absolute_url" methods to use "oldid" in place of "id".
That is not all problem you should overcome. GAE Datastore doesn't allow inequality filter on more than one fields. If you use it, you should change the logic. Some of them are solvable with result caching. If you use SQL directly for speed-up, it won't work. Some query take more time or doesn't return correct value and there is DeadlineExceededException. You need tune-up in GAE way. You can't know how much items in your Datastore if it is more than 1000, in such case count() always return 1000.
Three month before, I thought it is easy task. Now I am convinced that I should rewrite the app. I hope it helps some people like me.
Showing posts with label Google App Engine. Show all posts
Showing posts with label Google App Engine. Show all posts
2010-08-04
2010-05-27
FIX: ImportError: cannot import name ImmutableList
Hi, it is NISHIO Hirokazu. I'm moving my Django app into Google App Engine with Django-nonrel. I encountered the error and it took a lot of time from me. Google search didn't know anything about the problem.
The version of Django in Google App Engine is 1.0. Thus that of Django-nonrel(djangoappengine) is 1.2. It is the root of the problem.
Of cource, some code to avoid such a versioning problem was wrote in Django-nonrel. See djangoappengine/main/main.py
If sys.path doesn't have the path to Django in Django-nonrel, it add the path. If already old Django was imported, it remove that. But unfortunately, in my case, sys.path has the path, and the path to Django in Google App Engine preceded, but it's not imported yet.
It's mystery. I can't tell why it happened. But it actually happened.
I wrote a workaround for the problem. It bring the path to correct Django always on top.
The version of Django in Google App Engine is 1.0. Thus that of Django-nonrel(djangoappengine) is 1.2. It is the root of the problem.
Of cource, some code to avoid such a versioning problem was wrote in Django-nonrel. See djangoappengine/main/main.py
parent_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
f parent_dir not in sys.path:
sys.path.insert(0, parent_dir)
# Remove the standard version of Django
if 'django' in sys.modules and sys.modules['django'].VERSION < (1, 2):
for k in [k for k in sys.modules
if k.startswith('django\.') or k == 'django']:
del sys.modules[k]
If sys.path doesn't have the path to Django in Django-nonrel, it add the path. If already old Django was imported, it remove that. But unfortunately, in my case, sys.path has the path, and the path to Django in Google App Engine preceded, but it's not imported yet.
It's mystery. I can't tell why it happened. But it actually happened.
I wrote a workaround for the problem. It bring the path to correct Django always on top.
parent_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
if parent_dir in sys.path:
sys.path.remove(parent_dir)
sys.path.insert(0, parent_dir)
Label:
Django,
Django-nonrel,
Google App Engine,
NISHIO,
Python
FIX: DatabaseError: Non-nullable field id can't be None!
Hi, it is NISHIO Hirokazu. I'm moving my Django app into Google App Engine with Django-nonrel. I encountered the error and it took a lot of time from me. Google search didn't know anything about the problem.
Keep in mind: DON'T INHERIT DJANGO MODELS!
I want to add "oldid" field to keep relation information between models. Unfortunately "User" models are not mine, just be imported from django.auth, so I inherit it to add the field. It was the root of evil.
I hope it helps you :)
Keep in mind: DON'T INHERIT DJANGO MODELS!
I want to add "oldid" field to keep relation information between models. Unfortunately "User" models are not mine, just be imported from django.auth, so I inherit it to add the field. It was the root of evil.
I hope it helps you :)
Label:
Django,
Django-nonrel,
Google App Engine,
NISHIO,
Python
2010-04-16
How I fixed TemplateNotFound error
Hi, it is NISHIO Hirokazu! Yesterday I deployed my brand-new application with kay-framework, but it doesn't work. It said TemplateNotFound occured. It worked on my local server.
It came from very simple mistake! I used Deploy button on my GoogleAppEngineLauncher. It run "appcfg.py update" directly. However, we should not use "appcfg.py update" directly. Use "manage.py appcfg update".
Jinja2 (used in Kay) pre-parse templates and compile them to python codes. You can do it to run "manage.py preparse_apps". And when you do "manage.py appcfg update", it also do preparsing. Unfortunately I did "appcfg.py update" so the lack of preparsing phase caused TemplateNotFound.
It came from very simple mistake! I used Deploy button on my GoogleAppEngineLauncher. It run "appcfg.py update" directly. However, we should not use "appcfg.py update" directly. Use "manage.py appcfg update".
Jinja2 (used in Kay) pre-parse templates and compile them to python codes. You can do it to run "manage.py preparse_apps". And when you do "manage.py appcfg update", it also do preparsing. Unfortunately I did "appcfg.py update" so the lack of preparsing phase caused TemplateNotFound.
Label:
Google App Engine,
Kay,
NISHIO,
Python
Subscribe to:
Posts (Atom)