#21838 closed New feature (wontfix)
What about adding a .reload() method to the QuerySet API?
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.6 |
Severity: | Normal | Keywords: | queryset |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Sometimes it is needed to reload data from database backend. It could be necessary in example to benefit of some values type-casting applied by the database backend module.
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)
Change History (3)
comment:1 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:3 by , 6 years ago
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.
Version 0, edited 6 years ago by (next)
Note:
See TracTickets
for help on using tickets.
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.