Opened 6 years ago

Closed 6 years ago

#28830 closed New feature (wontfix)

Add a function to convert a list to a Queryset

Reported by: 0r1gamic Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: queryset, list
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Querysets can be converted to list. But list cannot be converted to query set. I wrote a new function in django.db.models.utils package.

from django.db.models.utils import list_to_queryset
queryset = list_to_queryset(object_list)

Change History (1)

comment:1 by Tim Graham, 6 years ago

Component: Core (Other)Database layer (models, ORM)
Resolution: wontfix
Status: newclosed
Summary: List to QuerysetAdd a function to convert a list to a Queryset
Type: UncategorizedNew feature

I don't think this merits inclusion in Django. The code is simple enough that it doesn't add much boilerplate for projects that want the behavior.

There are also several problems with the implementation that might be footguns:
1) Ordering isn't preserved.
2) For large lists, the performance of model.objects.filter(pk__in=pk_list) is usually poor.

Note: See TracTickets for help on using tickets.
Back to Top