For the moments bars represents a String with all the Bar ids with ';' separator
like 6;5;9;15
class Foo(db.Model):
id = db.StringProperty(multiline=True)
name = db.StringProperty(multiline=True)
bars = db.TextProperty()
class Bar(db.Model):
id = db.StringProperty(multiline=True)
name = db.StringProperty(multiline=True)
What must I do to explicit Foo contains some bars in db? And also how is going to look my :
f = Foo()
f.name= 'aName'
f.id = '3615'
f.bars = '6;5;9;15'
f.put()
For a start, you never want to store multiple values inside a single textfield. AppEngine's datastore supports multi-valued properties (such as
ListProperty
): you should use those.That said, there's no multi-valued equivalent of
ReferenceProperty
built in. This article on the AppEngine documentation site gives a good example of how to model a list of keys.Assuming this is a many-to-many relationship, you can use
db.ListProperty(db.Key)
for a list of theBar
s' Keys, or, if you really want to just store the integer IDs,db.ListProperty(int)
.If each
Bar
can only be a bar of a single foo, it's probably better to use aReferenceProperty
in theBar
entity, then use the automatic backreference inFoo
to get a query for all of the bars.By the way, naming a property "id" and making it a multiline string is probably a Bad Idea.