On Sun, Nov 29, 2009 at 5:49 PM, Robert Kluin <[email protected]> wrote:
> I think you can acheive the "back reference" by defining an instance
> method that returns a query object defined to search the other model
> for references to itself.   In fact I think that is all
> ReferenceProperty does anyway.
>
> Try something like this:
>
> class ModelA(db.Model):
>    def modelB_list(self):
>        if self.key():
>          refs = ModelB.all()
>          refs.filter('a_id_ref =', self.key().id())
>          return refs
>        return None
>
> class ModelB(db.Model):
>     a_ref_id = db.IntegerProperty()
>
> ma = ModelA()
> ma.put()
>
> mb1 = ModelB(a_id_ref=ma.key())
> mb2 = ModelB(a_id_ref=ma.key())
> db.put([mb1,mb2])
>
>
> for mb in ma.modelB_list:
>   print str(mb.key())
>
>
> Robert
i too use record.key().id() getting ok results empirically, blogged
how for dirty sitemap generator example (months b4 Agent Johnson did
it)
http://niklasro.blogspot.com/2009/08/sitemapxmlgz-generator.html

--

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.


Reply via email to