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.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Maybe `_clone()` already does what you need.
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:1>
* stage: Unreviewed => Accepted
Comment:
I guess we probably don't want to document an underscore method. I wonder
if there is any reason not to rename it (with deprecation) to `clone()` or
something similar?
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:2>
* component: Database layer (models, ORM) => Documentation
* easy: 0 => 1
Comment:
.all() can be used for this. Seems like this isn't documented, so lets do
that. The right place seems to be
https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.all.
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:3>
Comment (by nikisweeting@…):
I'd be happy to write a little blurb in the docs showing how to use .all()
for refreshing a QuerySet. I'm new to contributing to here though, how do
I go about submitting my proposed documentation amendment?
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:4>
Comment (by timo):
Fortunately, we have
[https://docs.djangoproject.com/en/dev/internals/contributing/ extensive
docs] that explains how to contribute. :-)
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:5>
* status: new => assigned
* owner: nobody => dhoffman
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:6>
Comment (by dhoffman):
Completed: https://github.com/django/django/pull/2974
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:7>
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
Comment:
Looks good. Don't forget to check "Has patch" so the ticket appears in the
review queue. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"6d5daa30cf29d0bada0586213ecb2959152566b4"]:
{{{
#!CommitTicketReference repository=""
revision="6d5daa30cf29d0bada0586213ecb2959152566b4"
Fixed #22553 -- Added refreshing queryset info to docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"e3a99357cba5085f5ae937920529292edafc5c7a"]:
{{{
#!CommitTicketReference repository=""
revision="e3a99357cba5085f5ae937920529292edafc5c7a"
[1.6.x] Fixed #22553 -- Added refreshing queryset info to docs.
Backport of 6d5daa30cf from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"1ef544f91f0d4be3f44ae7fd0498530e57a9b160"]:
{{{
#!CommitTicketReference repository=""
revision="1ef544f91f0d4be3f44ae7fd0498530e57a9b160"
[1.7.x] Fixed #22553 -- Added refreshing queryset info to docs.
Backport of 6d5daa30cf from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:11>