Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 580
MarcoB Avatar asked May 23 '10 19:05

MarcoB


2 Answers

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',
            })
like image 106
mechanical_meat Avatar answered Sep 20 '22 03:09

mechanical_meat


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

like image 44
Alex Martelli Avatar answered Sep 20 '22 03:09

Alex Martelli