0

If have a date picker form that filters a set of models (Sonde) and populates a ModelChoicesField. This works correctly in terms of date choice in my app, but on my canvas I constantly get the error:

Select a valid choice. That choice is not one of the available choices.

I do the init, to filter the available instances of Sonde and populate the choices of the ModelChoiceField.

From my forms.py

class date_choice(forms.Form):

    avSonden = forms.ModelChoiceField(queryset = Sonde.objects.none())

    def __init__(self, *args, **kwargs):
        currentUserID = kwargs.pop('currentUserID', None)
        super(date_choice, self).__init__(*args, **kwargs)

        if currentUserID:
            self.fields['avSonden'].queryset = Sonde.objects.filter(owned_by__Kundennummer = currentUserID).values_list("Serial",flat=True).distinct()

    start = forms.DateField(input_formats=['%Y-%m-%d'])
    end = forms.DateField(input_formats=['%Y-%m-%d'])
Benjamin Mewes
  • 89
  • 2
  • 10

1 Answers1

0

I had to force the clean() to ignore my change from PK to other identifier:

def clean_status(self):
    #valid if a value has been selected
    if self["avSonden"].value()!="":
        del self._errors["avSonden"]
    return self["avSonden"].value()
Benjamin Mewes
  • 89
  • 2
  • 10