Skip to content Skip to sidebar Skip to footer

What Is The Good Db Property, For An Keys's Array For Python With App Engine?

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.String

Solution 1:

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.

Solution 2:

Assuming this is a many-to-many relationship, you can use db.ListProperty(db.Key) for a list of the Bars' 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 a ReferenceProperty in the Bar entity, then use the automatic backreference in Foo 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.

Post a Comment for "What Is The Good Db Property, For An Keys's Array For Python With App Engine?"