Ticket #7475: models.py.diff

File models.py.diff, 797 bytes (added by esaj, 7 years ago)

Simple patch that fixes the race condition.

  • django/newforms/models.py

     
    285285    def __iter__(self):
    286286        if self.field.empty_label is not None:
    287287            yield (u"", self.field.empty_label)
    288         for obj in self.queryset:
     288        # TODO: Support self.field.cache_choices but beware of threading issues
     289        for obj in self.queryset.all():
    289290            yield (obj.pk, self.field.label_from_instance(obj))
    290         # Clear the QuerySet cache if required.
    291         if not self.field.cache_choices:
    292             self.queryset._result_cache = None
    293291
    294292class ModelChoiceField(ChoiceField):
    295293    """A ChoiceField whose choices are a model QuerySet."""
Back to Top