Django

Code

Changeset 3851

Show
Ignore:
Timestamp:
09/26/06 01:33:32 (2 years ago)
Author:
mtredinnick
Message:

Fixed #2265 -- Fixed problem with using iterators for "choices" attribute.
Thanks, Alex Dedul.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/fields/__init__.py

    r3844 r3851  
    66from django.core.exceptions import ObjectDoesNotExist 
    77from django.utils.functional import curry 
     8from django.utils.itercompat import tee 
    89from django.utils.text import capfirst 
    910from django.utils.translation import gettext, gettext_lazy 
     
    8182        self.unique_for_date, self.unique_for_month = unique_for_date, unique_for_month 
    8283        self.unique_for_year = unique_for_year 
    83         self.choices = choices or [] 
     84        self._choices = choices or [] 
    8485        self.radio_admin = radio_admin 
    8586        self.help_text = help_text 
     
    324325    def bind(self, fieldmapping, original, bound_field_class): 
    325326        return bound_field_class(self, fieldmapping, original) 
     327 
     328    def _get_choices(self): 
     329        if hasattr(self._choices, 'next'): 
     330            choices, self._choices = tee(self._choices) 
     331            return choices 
     332        else: 
     333            return self._choices 
     334    choices = property(_get_choices) 
    326335 
    327336class AutoField(Field):