Ticket #7475: models.3.py.diff
File models.3.py.diff, 1.4 KB (added by , 16 years ago) |
---|
-
django/newforms/models.py
285 285 def __iter__(self): 286 286 if self.field.empty_label is not None: 287 287 yield (u"", self.field.empty_label) 288 for obj in self.queryset: 289 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 288 if self.field.cache_choices: 289 if self.field.choice_cache is None: 290 self.field.choice_cache = [ 291 (obj.pk, self.field.label_from_instance(obj)) 292 for obj in self.queryset.all() 293 ] 294 for choice in self.field.choice_cache: 295 yield choice 296 else: 297 for obj in self.queryset.all(): 298 yield (obj.pk, self.field.label_from_instance(obj)) 293 299 294 300 class ModelChoiceField(ChoiceField): 295 301 """A ChoiceField whose choices are a model QuerySet.""" … … 311 317 Field.__init__(self, required, widget, label, initial, help_text, 312 318 *args, **kwargs) 313 319 self.queryset = queryset 320 self.choice_cache = None 314 321 315 322 def _get_queryset(self): 316 323 return self._queryset