开发者

How to cache a list of custom-defined models in Django?

I have a list of models, [Book1, Book2, Book3], that I need to cache. I get this error, when I try to cache them: can't pickle _Element objects Here is the c开发者_如何转开发ode that I am using:

if cache.get(isbn):
    sellers = cache.get(isbn)
else:
    sellers = get_all_amazon_sellers(isbn)
    cache.set(isbn, sellers, 600)

Thank you so much!


You might have to convert your data into a python list, as discussed here


May be some value in your list is special type, and not common python object. I met the same trouble when I want to pickle texts which are parsed with lxml.Some useful links:lxml question and my record.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜