Ticket #3196: choices_patch.diff

File choices_patch.diff, 894 bytes (added by Jason Prado <jason@…>, 9 years ago)

Adds a set_choices method to ChoiceField/MultiChoiceField

  • django/newforms/fields.py

     
    310310        Field.__init__(self, required, widget, label)
    311311        self.choices = choices
    312312
     313    def set_choices(self, choices):
     314        self.choices = choices
     315        self.widget.choices = choices
     316
    313317    def clean(self, value):
    314318        """
    315319        Validates that the input is in self.choices.
     
    328332    def __init__(self, choices=(), required=True, widget=SelectMultiple, label=None):
    329333        ChoiceField.__init__(self, choices, required, widget, label)
    330334
     335    def set_choices(self, choices):
     336        self.choices = choices
     337        self.widget.choices = choices
     338
    331339    def clean(self, value):
    332340        """
    333341        Validates that the input is a list or tuple.
Back to Top