Django

Code

Ticket #4787: ModelChoiceField_update_choices.diff

File ModelChoiceField_update_choices.diff, 1.2 kB (added by eads, 1 year ago)
  • django/newforms/models.py

    old new  
    141141    # actually use any of ChoiceField's implementation. 
    142142    def __init__(self, queryset, empty_label=u"---------", cache_choices=False, 
    143143            required=True, widget=Select, label=None, initial=None, help_text=None): 
    144         self.queryset = queryset 
     144        self._queryset = queryset 
    145145        self.empty_label = empty_label 
    146146        self.cache_choices = cache_choices 
    147147        # Call Field instead of ChoiceField __init__() because we don't need 
     
    149149        Field.__init__(self, required, widget, label, initial, help_text) 
    150150        self.widget.choices = self.choices 
    151151 
     152 
     153    def _get_queryset(self): 
     154        return self._queryset 
     155 
     156    def _set_queryset(self,queryset): 
     157        self._queryset = queryset 
     158        self.widget.choices = self.choices 
     159 
     160    queryset = property(_get_queryset,_set_queryset) 
     161 
    152162    def _get_choices(self): 
    153163        # If self._choices is set, then somebody must have manually set 
    154164        # the property self.choices. In this case, just return self._choices.