StringListProperty限制为500个字符串(Google App Engine / Python)

时间:2010-05-23 19:28:09

标签: python google-app-engine

似乎StringListProperty每个字符串最多只能包含500个字符,就像StringProperty ...

有没有办法存储比这更长的字符串?我不需要它们被索引或任何东西。我需要的是“TextListProperty”,其中列表中的每个字符串可以是任意长度,不限于500个字符。

我可以创建这样的属性吗?或者您可以专家建议一种不同的方法吗?也许我应该使用普通列表并在Blob字段中腌制/取消它,或类似的东西?我对Python和GAE有点新意,我非常感谢一些指示,而不是花费几天试用和错误......谢谢!

2 个答案:

答案 0 :(得分:4)

亚历克斯很久以前就已经回答了,但万一其他人也有同样的问题:

你只需要使item_type等于db.Text(在评论中提到OP)。
这是一个简单的例子:

from google.appengine.ext import db
class LargeTextList(db.Model):
    large_text_list = db.ListProperty(item_type=db.Text)

def post(self):
    # get value from a POST request, 
    # split into list using some delimiter
    # add to datastore
    L = self.request.get('large_text_list').split() # your delimiter here
    LTL = [db.Text(i) for i in L]
    new = LargeTextList()
    new.large_text_list = LTL
    new.put()

def get(self):
    # return one to make sure it's working
    query = LargeTextList.all()
    results = query.fetch(limit=1)
    self.render('index.html', 
            {   'results': results, 
                'title': 'LargeTextList Example',
            })

答案 1 :(得分:2)

您可以根据需要使用item_type str通用unicode,{{1}}或其他任何内容。