views:

129

answers:

2

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!

+2  A: 

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

Alex Martelli
Both str and unicode are also limited to 500 chars. But then I tried with db.Text as a type, and so far it seems to work. Thanks for pointing me in the right direction.
MarcoB
A: 

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',
            })
Adam Bernier
Thanks for the code, that is the way to go. One thing to keep in mind is that every assignment must be typecast to db.Text or the compiler will throw an exception. Even to assign an empty string one has to do, for example: object.text_list.append(db.Text(""))
MarcoB