class Post(db.Model):
title = db.StringProperty()
body = db.TextProperty()
def categories(self):
map(lambda x: x.category, self.categorization_set)
class Category(db.Model):
name = db.StringProperty()
def posts(self):
map(lambda x: x.post, self.categorization_set)
class Categorization(db.Model):
post = db.ReferenceProperty(Post)
category = db.ReferenceProperty(Category)
Then you can do stuff like this:
p = Post.get_by_id(1)
for c in p.categories():
print c.name
Obviously there is controller glue missing here... I also don't know
if there's a better/recommended way to handle this with appengine.
Regards,
Jeremey.
Oops... need a return in there:
def categories(self):
return map(lambda x: x.category, self.categorization_set)
etc.
Jeremey.
| /home/peter/projects/gae/google_appengine/google/appengine/ext/db/__init__.py in __property_config__(self=<google.appengine.ext.db.ReferenceProperty object at 0x1d1e910>, model_class=<class 'models.Task'>, property_name='responsible') |
| 2194 raise DuplicatePropertyError('Class %s already has property %s' |
| 2195 % (self.reference_class.__name__, |
| 2196 self.collection_name)) |
| 2197 setattr(self.reference_class, |
| 2198 self.collection_name, |
| self = <google.appengine.ext.db.ReferenceProperty object at 0x1d1e910>, self.collection_name = 'task_set' |
<class 'google.appengine.ext.db.DuplicatePropertyError'>: Class User already has property task_set
args =
('Class User already has property task_set',)
message =
'Class User already has property task_set'
Can anyone help?
Thx!
PS
Thanks... the list comprehension is much better, I dunno why I tend
to forget that Python does that.. :)
Jeremey.
Jeremey.
created_by = db.ReferenceProperty(User, collection_name='created_tasks')
Or somesuch.
Or maybe there's a way to suppress the backreferencing altogether, I don't
know off the top of my head.
Jeremey.