views:

277

answers:

1

I have some models set up like:

class Apps(db.Model):
    name        = db.StringProperty(multiline=False)
    description = db.TextProperty()

class AppScreenshots(db.Model):
    image_file     = db.StringProperty(multiline=False)
    description    = db.StringProperty(multiline=False)
    app            = db.ReferenceProperty(Apps)

I'm trying to reference a "parent" app in a screenshot like so:

a = Apps.get(app_key)   
ss = AppScreenshots(
    image_file     = 'foo',
    description    = 'bar',
    app            = a
)
ss.put()

But it complains to me saying:

BadArgumentError('_app should be a string; received ag1raWxsZXItcm9ib3RzcgoLEgRBcHBzGAkM (a Key):',)

I've tried going over a few examples on the internet and they all seem to work JUST like the above. One set of documentation Google has up suggests doing it a little differently, like this:

a = Apps.get(app_key)   
ss = AppScreenshots(
    image_file     = 'foo',
    description    = 'bar',
    app            = a.key()
)
ss.put()

But that gives me the exact same error.

What am I doing wrong?

+5  A: 

The problem I found when trying to run your code was that apparently you need to change the name of 'app' in AppScreenshots to something else such as 'apps'. The word 'app' must be reserved in this context.

Try this Query instead. You could do .filter() too on this if you don't want the first entity.

class AppScreenshots(db.Model):
     image_file     = db.StringProperty()
     description    = db.StringProperty()
     apps            = db.ReferenceProperty(Apps)

appsObject = db.Query(Apps).get()

ss = AppScreenshots(image_file = 'foo', description = 'bar',apps = appsObject)

Here is a helpful article on modeling relationships link.

Also a related question here on SO

Jason Rikard
Hey yeah... I moved it to parent_app and it worked fine. Thanks!
fiXedd
Wish I had figured that out last night ;)
fiXedd
Glad I could help.
Jason Rikard