Hey, I have a model like this:
class List(db.Model):
user = db.ReferenceProperty(User)
listname = db.StringProperty()
published = db.DateTimeProperty(auto_now_add=True)
score = db.IntegerProperty(required=False)
tld = db.StringProperty(required=False)
categories = db.StringListProperty()
Where a list could have multiple categories attached to it (hence the listproperty). I want to use these categories to build category pages so I need a query I can use to fetch all lists that have a particular category within their categories attribute. I've tried a few different approaches and none seem to work. Is there a query like this this? (the following doesn't work):
selec开发者_JS百科t * from List where 'Philosophy' in categories
If not, I'm going to have to do something like:
lists = List.all()
for list in lists:
if 'Philosophy' in list.categories:
#add this list to the lists to display on page
But this feels like it would be either incredibly slow or break somehow...
Any ideas? Thanks!
Tom
UPDATE:
Oops, I solved it sorry for the bother! For anyone who's interested you can just use a query like this:
SELECT * FROM List where categories = 'Philosophy'
Which will match any list which has 'Philosophy' within the categories.
Oops, I solved it sorry for the bother! For anyone who's interested you can just use a query like this:
SELECT * FROM List where categories = 'Philosophy'
Which will match any list which has 'Philosophy' within the categories.
精彩评论