On Wed, Jul 8, 2009 at 12:27 PM, Adam Olsen <arol...@gmail.com> wrote:
> > class ValidParameter(models.Model): > # .. fields > > class ValidRequest(models.Model): > # ... fields > optional = models.ManyToManyField(ValidParameter, null=True, > blank=True) > > > ----------------------------------------- > > Given the above models, I'd like to be able to do something like this: > > from django.core.cache import cache > import pickle > request = models.ValidRequest.objects.select_related().get(pk=1) > > cache.set("woot", pickle.dumps(request)) > > request = cache.get("woot") > > # and have this not hit the database: > > [x for x in request.optional.all()] > > Is there a way to do this easily, or should I just cache the parameters > manually? > > -- > Adam Olsen > SendOutCards.com > http://www.vimtips.org > http://last.fm/user/synic > > > > ManyToMany relations aren't stored locally the same way a ForeignKey is, since we use teh QuerySet API to access it. The easiest way to work around this is to just setup a property/method on the Model class that pulls in the queryset and caches it on the model and always use that instead of teh default manager, that way when you cache the obj if it has a local cache it will be stored. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---