Ticket #2265: iterator_choices.patch

File iterator_choices.patch, 1.4 KB (added by Alex Dedul, 18 years ago)
  • django/db/models/fields/__init__.py

     
    77from django.utils.functional import curry, lazy
    88from django.utils.text import capfirst
    99from django.utils.translation import gettext, gettext_lazy, ngettext
    10 import datetime, os, time
     10import datetime, os, time, itertools
    1111
    1212class NOT_PROVIDED:
    1313    pass
     
    8080        self.prepopulate_from = prepopulate_from
    8181        self.unique_for_date, self.unique_for_month = unique_for_date, unique_for_month
    8282        self.unique_for_year = unique_for_year
    83         self.choices = choices or []
     83        self._choices = choices or []
    8484        self.radio_admin = radio_admin
    8585        self.help_text = help_text
    8686        self.db_column = db_column
     
    321321    def bind(self, fieldmapping, original, bound_field_class):
    322322        return bound_field_class(self, fieldmapping, original)
    323323
     324    def _get_choices(self):
     325        if hasattr(self._choices, 'next'):
     326            choices, self._choices = itertools.tee(self._choices, 2)
     327        else:
     328            choices = self._choices
     329
     330        return choices
     331    choices = property(_get_choices)
     332
    324333class AutoField(Field):
    325334    empty_strings_allowed = False
    326335    def __init__(self, *args, **kwargs):
Back to Top