Hi,
I'm not sure exactly your use case, so I'm just going to describe in general
what I might do in a similar situation.
Say I have a list of keys for a picture model, and I want to render that
picture on my HTML page. So, let's assume these are my models:
class FirstModel(db.Model)
my_pics = ListProperty(db.Keys)
class MyPic(db.Model)
picture = BlobProperty()
Assume I've have an instance of FirstModel, my_model, and I want to
construct links to images for my HTML template. I'd do something like this:
for picture_key in my_model.my_pics:
image_links.append('<img src="/img?key=%s"/>' % str(picture_key))
The I would have an Image request handler that was something along the lines
of:
class Image(webapp.RequestHandler):
def get(self):
img_key = self.request.get('key')
img = MyPic.get(img_key)
self.response.headers['Content-Type'] = 'image/jpg'
self.response.out.write(img.picture)
Obviously this is not production ready code, but you get the idea...
-Marzia
On Thu, Oct 2, 2008 at 4:03 AM, Nate Dog <[EMAIL PROTECTED]> wrote:
>
> Hi Mariza,
>
> ive been having the same issue as ARMIX,
>
> my question is i have a page model one of the page models propertys is
> a field called pics which is a list property
> im storing a list ok keys from a photo model ... the idea is page has
> a number of photos.
>
> from what your saying i think ill need to loop through my list and do
> a new query per list item as oposed to using the GQL IN syntax to try
> and match the photo model's key with my list of keys from my page.pics
> property
>
> is that correct or is there a way to use a Kinds/Models key in GQL ?
>
> On Aug 23, 2:55 am, "Marzia Niccolai" <[EMAIL PROTECTED]> wrote:
> > Hi Armin,
> > You can't query for the key, there is really no need. If you know the
> key
> > for the entity you want just do:
> >
> > entity = MyModel.get(key)
> >
> > Thats all there is to it.
> >
> > -Marzia
> >
> > On Fri, Aug 22, 2008 at 7:43 AM, ARMIX <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > > I'm new to App Engine, new to python and have some problems with the
> > > datastore. :)
> > > I'd like to query a record from the Datastore where the field "user" =
> > > users.get_current_user() and the field "key" =
> > > "agNhd25yCgsSBE5vdGUYBww"
> > > ... so the Query looks like:
> > > notes = db.GqlQuery("SELECT * FROM Note WHERE user = :1 AND key = :2
> > > LIMIT 1", users.get_current_user(), key)
> > > ...but that doesn't work.
> >
> > > If I submit the same query without the "AND key = :2" it works fine.
> > > It seems that it is not possible to query for the entity key? Is that
> > > right? And if yes, how can I get the requested record?
> >
> > > Until now I tried the following queries without success:
> > > notes = db.GqlQuery("SELECT * FROM Note WHERE user = :1 AND key = :2
> > > LIMIT 1", users.get_current_user(), key)
> > > notes = db.GqlQuery("SELECT * FROM Note WHERE user = :1 AND id = :2
> > > LIMIT 1", users.get_current_user(), "7")
> > > notes = db.GqlQuery("SELECT * FROM Note WHERE user = :1",
> > > users.get_current_user())
> > > notes = Note.get_by_key_name(key)
> > > notes = Note.get(db.key.from_path('Note', key)
> > > notes = Note.get_by_key_name("agNhd25yCgsSBE5vdGUYBww")
> > > notes = db.get("agNhd25yCgsSBE5vdGUYBww")
> >
> > > Sometimes I got the following error: 'Note' object is not iterable
> >
> > > The class "Note":
> > > class Note(db.Model):
> >
> > > user = db.UserProperty()
> >
> > > subj = db.StringProperty(multiline=False)
> >
> > > text = db.StringProperty(multiline=True)
> >
> > > tscrt = db.DateTimeProperty(auto_now_add=True)
> >
> > > tschg = db.DateTimeProperty(auto_now=True)
> >
> > > Can anybody help me please?
> >
> > > Thanks,
> > > Armin
> >
> >
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" 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/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---