Changes between Initial Version and Version 1 of Ticket #27001, comment 3
- Timestamp:
- Aug 2, 2016, 10:30:39 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #27001, comment 3
initial v1 1 1 Created a pull request with a fix. 2 2 3 `ChoiceFieldRenderer` doesn't have `__iter__` defined, so Python iterates over it by calling `__getitem__` with an increasing index until an exception is raised. `ChoiceFieldRenderer.__getitem__` calls `list` on itself, which turns iteration into an n^2 operation. When the choices are backed by a queryset as in ModelChoiceField, that means lots of redundant database queries.3 `ChoiceFieldRenderer` doesn't have `__iter__` defined, so Python iterates over it by calling `__getitem__` with an increasing index until an exception is raised. `ChoiceFieldRenderer.__getitem__` calls `list` on itself, which turns iteration into an n^2^ operation. When the choices are backed by a queryset as in ModelChoiceField, that means lots of redundant database queries. 4 4 5 5 Fixed by adding an `__iter__` method to `ChoiceFieldRenderer` and changing `__getitem__` to use it, so that indexing still works.