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.
精彩评论