gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:03:57 25 4
gpt4 key购买 nike

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

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

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

最佳答案

Alex 早就回答过了,但如果其他人遇到同样的问题:

您只需使 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',
})

关于python - StringListProperty 限制为 500 个字符字符串(Google App Engine/Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2893102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com