Ticket #5830: modelchoicefield_queryset_as_property.diff

File modelchoicefield_queryset_as_property.diff, 1.2 KB (added by Øyvind Saltvik <oyvind@…>, 11 years ago)

queryset as property

  • django/newforms/models.py

     
    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
    145144        self.empty_label = empty_label
    146145        self.cache_choices = cache_choices
    147146        # Call Field instead of ChoiceField __init__() because we don't need
    148147        # ChoiceField.__init__().
    149148        Field.__init__(self, required, widget, label, initial, help_text)
     149        self.queryset = queryset
     150
     151    def _get_queryset(self):
     152        return self._queryset
     153
     154    def _set_queryset(self, queryset):
     155        self._queryset = queryset
    150156        self.widget.choices = self.choices
    151157
     158    queryset = property(_get_queryset, _set_queryset)
     159
    152160    def _get_choices(self):
    153161        # If self._choices is set, then somebody must have manually set
    154162        # the property self.choices. In this case, just return self._choices.
Back to Top