#22553: Add ability to refresh queryset ----------------------------------------------+-------------------- Reporter: giggaflop@… | Owner: nobody Type: New feature | Status: new Component: Database layer (models, ORM) | Version: 1.6 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+-------------------- I propose adding a Queryset method '.refresh()' which will clear the built-in cache on any queryset passed to it.
I suggest an initial implementation of: {{{ def refresh(self, *args, **kwargs): """ Returns a new QuerySet instance with the args ANDed to the existing set. """ self._result_cache = None return self }}} Reason this is requested: When I'm using modelformsets I typically find the need to refresh the queryset that is used by the ModelFormset. To do this I perform the following action: {{{ updated_formset = ConciergeUserPoolFormset(request.POST) if updated_formset.is_valid(): updated_formset.save() queryset = updated_formset.get_queryset() # we need an updated queryset, not the cached version. set the results cache to None to force re-fetch queryset._result_cache = None updated_formset = ConciergeUserPoolFormset(queryset=queryset) }}} This is not an obvious solution to the issue of updating a ModelFormset or forcing a queryset update in general, it also uses a private method of the Queryset object which I would prefer to avoid. -- Ticket URL: <https://code.djangoproject.com/ticket/22553> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/062.1b765b650489b58748c13df1bf35c2d2%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.