Saving objects in django-nerel using google appengine

Update: I noticed that objects are saved (and available in the data warehouse viewer) when I save them using views (and the create_object function). But when I use the shell (manage.py shell) to create and save a new object, it is not bound to the repository (but can still be seen in Tes.objects.all ()).


I started playing django-nerel with the Google appengine, and I get upset with things as easy as saving entities.

I installed my environment as described in the instructions . I managed to run the sample application and it works fine. I would like to expand it so that it saves my essence in storage. For this:

  • I added a new django module with models.py:

    from django.db import models class Tes(models.Model): name = models.CharField(max_length=150) 
  • I created a script to save some data:

     import os import sys sys.path.append("d:\\workspace\\project\\") os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from testmodule.models import Tes t = Tes(name="test") t.save() tes = Tes.objects.all() for t in tes: print t.name 

The script works without errors. When I run it several times one by one, it prints more and more β€œtest” lines. But when I try to start it after a minute break, Tes.objects.all () returns nothing. During this time, the data warehouse file will change its size (but maybe it's just some kind of logs). When I look at http: // localhost: 8000 / _ah / admin / datastore , I can only select AhAdminXrsfToken from the selection box.

Anyway, what am I missing? Where can I find some magazines that will tell me what is wrong?

+6
source share
2 answers

This is magic that causes a lot of confusion. From djangoappengine docs :

Also, never run run.py runerver with another command control at the same time. Changes will not take effect. This is the App Engine SDK, which may be fixed in a later release.

Thus, you cannot do manage.py runserver and manage.py shell at the same time. If you do this, changes to the data warehouse in one will not be visible in the other. There is a local data storage lock provided by the App Engine SDK. Before starting the shell, make sure you stop the server.

+4
source

Wouldn't that be t.put() if you create an entity and not save it? I use put() to create an object, and it works for me. And if you import django, you may know that there are alternatives to django, such as my choice of GAE + Jinja2 + WTForms, especially now that google.db.djangoforms is deprecated, choosing the form structure for the forms, the template engine, and possibly the db structure and you do not need to import django, which often leads to the fact that you import much more than you need.

Therefore, I recommend avoiding import django... and use Jinja2 + WTForms instead. If you really want django in the application, then you can check out the project www.allbuttonspressed.com, which allows all django for the Google engine, but be sure that you need a lot of django when I suspect that all we need is template engine and form framework, and we can do without django.

-1
source

Source: https://habr.com/ru/post/902104/


All Articles