appcfg.py upload_data entity kind problem
I am developing application on app-engine-path and I would like to upload some data to datastore. For example I have a model
models/places.py:
class Place(db.Model):
name = db.StringProperty()
longitude = db.FloatProperty()
latitude = db.FloatProperty()
If I save this in view, kind() of this entity is "models_place". All is ok, Place.all() in view work fine.
But:
If I upload some next row using appcfg.py 开发者_JAVA百科upload_data, the kind() of this entities is Place.
loader.py look like this:
import datetime, os, sys
from google.appengine.ext import db
from google.appengine.tools import bulkloader
libs_path = os.path.join("/home/martin/myproject/src/")
if libs_path not in sys.path:
sys.path.insert(0, libs_path)
from models import places
class AlbumLoader(bulkloader.Loader):
def __init__(self):
bulkloader.Loader.__init__(self, 'Place',
[('name', lambda x: x.decode('utf-8')),
('longitude', float),
('latitude', float),
])
loaders = [AlbumLoader]
and command for uploading:
python /usr/local/google_appengine/appcfg.py upload_data --config_file=places_loader.py --kind=models_place --filename=data/places.csv --url=http://localhost:8000/remote_api /home/martin/myproject/src/
I found resolution:
places_loader.py:
from google.appengine.ext import bulkload
class PlaceLoader(bulkload.Loader):
def __init__(self):
bulkload.Loader.__init__(self, 'models_place',
[('name', lambda x: x.decode('utf-8')),
('longitude', float),
('latitude', float),
])
if __name__ == '__main__':
bulkload.main(PlaceLoader())
app.yaml:
- url: /load
script: places_loader.py
and command:
python /usr/local/google_appengine/bulkload_client.py --filename data/places.csv --kind models_place --url http://localhost:8000/load
精彩评论