Ok, for the benefit of those with similar problems in the future, here
is what I learned.  Yes, I know that this is all in the doc, but it is
spread around and hard to find in one place.  This all assumes the
default settings that come with the sample app.

- Entity names used in db calls of the form Shop.all() are
automatically prefixed with the name of the application that creates
them
- Entity names used in db calls of the form Shop.all() are translated
into all lower case
- None of this applies to entities created via the bulk uploader
- None of this applies to queries made with direct calls to GqlQuery

So to access an entity of type Shop from application myapp (which are
stored in the datastore as entities of type "myapp_shop"), you do this
query:

ShopList = db.GqlQuery("SELECT * FROM myapp_shop WHERE ... )

or make one of these calls

item = get_object(Shop, id = 5003)
ShopList = Shop.all()

When you upload entities via the bulk-uploader from the main
application directory (not the myapp subdirectory), you need to prefix
and lowercase them yourself - so the entity name in the loader has to
be myapp_shop as in:

bulkloader.Loader.__init__(self, 'myapp_shop', ...

And you call the uploader with that entity name as well as in:

appcfg.py --config_file=ShopLoader.py --filename=repair.csv --
kind=myapp_shop upload_data .

On Dec 10, 12:29 pm, Dan <[email protected]> wrote:
> Ok, figured out that one of my problems was that the entities I
> uploaded were of type Shop, but that the app was probably looking for
> entities of type myapp_Shop .  I uploaded a set of entities of that
> type, and got no better results.
>
> It seems that if I use item = get_object() then what I get back is an
> item that isn't of type Shop (so when I try item.name I get an
> attribute error).
>
> If I use ShopList = Shop.all() I get back an empty result set.
>
>                            ***dan
>
> On Dec 10, 11:15 am, Dan <[email protected]> wrote:
>
> > My confidence is high that I am just being an idiot, but I've now
> > spent several hours on this without luck. I have zero experience with
> > either Python, Django or App-Engine - just trying to get something
> > very simple started so I can learn.
>
> > I have successfully bulk uploaded about 20 entities of type Shop into
> > the datastore.  I can see them and query them via the browser based
> > application Data Viewer.
>
> > I cannot figure out how to get access to them from my application.
>
> > in model.py:
>
> > from google.appengine.ext import db
> > class Shop(db.Model) :
> >         name = db.StringProperty(required=True)
> >         description = db.TextProperty()
> >         location = db.GeoPtProperty()
> >         address1 = db.PostalAddressProperty()
> >         address2 = db.StringProperty()
> >         address3 = db.StringProperty()
> >         city = db.StringProperty()
> >         state = db.StringProperty()
> >         zip = db.IntegerProperty()
> >         address = db.PostalAddressProperty()
> >         phone = db.PhoneNumberProperty()
> >         myRating = db.RatingProperty(choices=[0,1,2,3], default=0)
> >         userRating = db.RatingProperty()
> >         url = db.LinkProperty()
> >         email = db.EmailProperty()
> >         uploaded = db.DateTimeProperty()
> >         def __unicode__(self):
>
> > in view.py
>
> > from google.appengine.ext import db
> > from myapp.models import  Shop
> > from ragendja.dbutils import get_object_list, get_object
> > from django.http import HttpResponse
> > from django.views.generic.list_detail import object_list,
> > object_detail
> > from ragendja.template import render_to_response
> > from django.template import Context, loader
>
> > def get_shop_by_state(request, state):
> > #       ShopList = get_object_list(Shop, 'state =', state)
> > #       ShopList = Shop.all()
> > #       ShopList = db.GqlQuery("SELECT * FROM Shop WHERE state = 'FL'")
> >         item = get_object(Shop, id=2005)
> > #       query = Shop.gql("WHERE state = 'FL'")
> > #       results = query.fetch(10)
> > #       t = loader.get_template('shops.html')
> > #       c = Context({
> > #               'NewShopList': ShopList,
> > #       })
> > #       return HttpResponse(t.render(c))
> >         return HttpResponse("Got State = " + item.state)
> > #       return object_list(request, results, paginate_by=10)
>
> > You can see that I've tried several different approaches (Shop.all(),
> > db.GqlQuery(), get_object()) - none of them work.
>
> > Eventually, I want to be able to query the datastore (for example, to
> > find all of the shops in a given state), and then output that list via
> > a template.  For now, I'd be happy if someone can tell me why the code
> > above, which seems like the most simple possible case, doesn't work.
>
> > Thanks!

--

You received this message because you are subscribed to the Google Groups 
"app-engine-patch" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/app-engine-patch?hl=en.


Reply via email to