1

In GAE-python, you can model a one-to-many relationship by assigning a reference property to the child model.

class Book(db.Model):
   title = db.StringProperty()
class Author(db.Model):
   book = db.ReferenceProperty(Book, collection_name = 'authors')
   is_primary = db.BooleanProperty()
   name = db.StringProperty()

This way, I can access the authors property of a book object instance to get a query-able list of all the Author instances that reference it.

What I want to do is supplement the authors property with a method. A trivial example based on the preceding one would be a function that returns just the primary authors sorted in alphabetical. What's the syntax for something like this?

1
  • 3
    Your question is very vague. Please explain what do you mean by "collection of entities". Do you mean classes? Is this RPC? Mixin?
    – Escualo
    Aug 17, 2010 at 18:57

1 Answer 1

0

What you are looking for is one to many realtionship. There is no db.Referencelist property.I guess this will help you out.

class Book(db.Model):
   title = db.StringProperty()
class Author(db.Model):
   is_primary = db.BooleanProperty()
   name = db.StringProperty()

book = Book(title="what is life")
book.put()

author1 = Author(parent=book,is_primary=true,name='author1')
author1.put()

author2 = Author(parent=book,is_primary=true,name='author2')
author2.put()

# from book to authors
book_authors = Author.all().ancestor(book)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.