Sibyx / django_api_forms

Declarative Django request validation for RESTful APIs

Home Page:https://sibyx.github.io/django_api_forms/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in `clean_` methon

Serbel97 opened this issue · comments

When you check values in clean_ method in Form, sometimes it returns None value.

class NewAlbumForm(Form):
    album_id = forms.ModelChoiceField(queryset=Album.objects.all(), required=True)
    scheduled_at = fields.DateField(required=True)

    def clean_album_id(self):
        if self.cleaned_data.get('album_id').type in [Album.AlbumType.CD]:
        # if self.cleaned_data.get('album_id').type != Album.AlbumType.CD:
            self.add_error(
                'album_id',
                ValidationError('You did not select CD', code='not-cd')
            )
        else:
            return self.cleaned_data['album_id']

Fixed in #42