0

In my django application I have a model field called 'status'. In one of the forms to get data for this field, I only want to display a subset of all choices available in the model. Is there a way to remove a choice from a form? I need the removed choice in the database and the admin interface where I can select it.

status = models.CharField(STATUS_FIELD_NAME, choices=STATUS_CHOICES,
                          default=STATUS_DEFAULT,
                          max_length=3)
dan1st
  • 12,568
  • 8
  • 34
  • 67
paweloque
  • 18,466
  • 26
  • 80
  • 136

1 Answers1

0

You could define the subset of choices in your form:

class YourForm(forms.ModelForm):
    SUBSET_CHOICES = (
        (YourModel.CHOICE_ONE, _('First choice')),
        (YourModel.CHOICE_TWO, _('Second choice')),
    )

    class Meta:
        model = YourModel
        fields = ['choice', ]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['choice'].choices = self.SUBSET_CHOICES
user42488
  • 1,140
  • 14
  • 26