Skip to content

Instantly share code, notes, and snippets.

@SakuradaJun
Forked from bsnux/gist:4672788
Last active August 29, 2015 14:08
Show Gist options
  • Save SakuradaJun/adf3532b111763f9635b to your computer and use it in GitHub Desktop.
Save SakuradaJun/adf3532b111763f9635b to your computer and use it in GitHub Desktop.
import pickle
# Session key
key = 'my_qs'
# Pizza => model example
qs = Pizza.objects.filter(ingredient='tomato')
# Dumping data
request.session[key] = pickle.dumps(qs.query)
# Loading data
pizzas = Pizza.objects.all()[:1]
pizzas.query = pickle.loads(request.session[key])
# Using qs
for pizza in pizzas:
print(pizza.ingredient)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment