In various Django projects I developed I find useful a simple method
QuerySet.reload() like this:
{{{
def reload(self):
"""Reload QuerySet from backend."""
pks_list = self.values_list('pk')
return self.model.objects.filter(pk__in=pks_list)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21838>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_better_patch: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_docs: => 0
Comment:
This will be very inefficient for large querysets. I'm -1 on this
implementation.
As far as I know, the easiest way to reload a QuerySet is simply
`qs.filter()`.
It will clone the queryset and wipe the result cache.
You may get different rows if the database has changed since the QuerySet
was first evaluated. That's the behavior I would expect.
--
Ticket URL: <https://code.djangoproject.com/ticket/21838#comment:1>
Comment (by fero@…):
Thanks I checked it out, I didn't know about this feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/21838#comment:2>
Comment (by Rich Rauenzahn):
FYI: This is a duplicate of https://code.djangoproject.com/ticket/22553
filed a year later that suggests using .all(), and fixes the docs to point
that feature out.
--
Ticket URL: <https://code.djangoproject.com/ticket/21838#comment:3>