开发者

StringListProperty limited to 500 char strings (Google App Engine / Python)

开发者 https://www.devze.com 2022-12-31 03:18 出处:网络
It seems that StringListProperty can only contain strings up to 500 chars each, just like StringProperty...

It seems that StringListProperty can only contain strings up to 500 chars each, just like StringProperty...

Is there a way to store longer strings than that? I don't need them to be indexed or anything. What I would need would be something like a "TextListProperty", where each string in the list can be any length and not limited to 500 chars.

Can I create a property like that? Or can you experts suggest a different approach? Perhaps I should use a 开发者_运维百科plain list and pickle/unpickle it in a Blob field, or something like that? I'm a bit new to Python and GAE and I would greatly appreciate some pointers instead of spending days on trial and error...thanks!


Alex already answered long ago, but in case someone else comes along with the same issue:

You'd just make item_type equal to db.Text (as OP mentions in a comment).
Here's a simple example:

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',
            })


You can use a generic ListProperty with an item_type as you require (str, or unicode, or whatever).

0

精彩评论

暂无评论...
验证码 换一张
取 消