Bill G.
Bill G.

Reputation: 1457

Is it possible to have multi-value field in Google App Engine Datastore?

I would like to have a GAE-Python Datastore Kind for something similar to a Blog and I would like to have a field for Categories or Tags where there can be multiple Tags for a given Blog instance. I am a GAE/Python newbie and am trying to find a way to be able to assign multiple categories for a single instance.

e.g.

class MyModel(db.Model):
    category = db.CategoryProperty()

How would I modify this to enable multiple categories for a MyModel instance?

If this is possible, what would a query to retrieve the instances for a single category value look like?

What would a "put" with multiple values for this field look like?

Thanks in advance for any suggestions or links to where I can find applicable documentation..

Upvotes: 2

Views: 540

Answers (3)

Gianni Di Noia
Gianni Di Noia

Reputation: 1578

If you are starting now with this project consider NDB and repeated property

class MyModel(ndb.Model):
category = ndb.StringProperty(repeated=True)

Upvotes: 5

Niks Jain
Niks Jain

Reputation: 1647

You can also use TextProperty to store any kind of values in list or in dict or in combination of list-dict or so..

Upvotes: 1

Haldean Brown
Haldean Brown

Reputation: 12711

You can use a ListProperty or a StringListProperty to store a list of categories; these store a list (or a list of strings) and you can use the property values just like you would normally use a list in Python.

Upvotes: 1

Related Questions