Is it possible to saw or somehow store a django request in a database? This will not work:
u = User.objects.all import cPickle pickled_query = cPickle.dumps(u)
Any thoughts?
Updated:
import cPickle class CustomData(models.Model): name = models.CharField(max_length = 30) pickled_query = models.CharField(max_length = 300) def get_custom_result(self): q = cPickle.loads(self.pickled_query) return q() >>> cd = CustomData(name="My data", pickled_query=cPickle.dumps(User.objects.all)) >>> cd.save() >>> for item in cd.get_custom_result(): print item
Now what I want to do. I know that this actual piece of code did not run, but it shows my intention; to save the query, not the result, and execute that query at some point in the future.
Update # 2:
>>> from django.contrib.auth.models import User
Still not done. I know QuerySets are lazy, so s2.model.objects.all () will not execute a query that gets all users?
source share