class ModelSerializerMixin(object):
    """Provides generic model serializer classes to views."""
    model_serializer_class = None

    def get_serializer_class(self):
        if self.serializer_class:
            return self.serializer_class
        class DefaultSerializer(self.model_serializer_class):
            class Meta:
                model = self.queryset.model
        return DefaultSerializer


class QueryFormMixin(object):
    """Provides form based handling of GET or POST requests."""
    query_form_class = None

    def get_query_form(self):
        """Returns a bound form instance."""
        return self.query_form_class(
            self.request.query_params or self.request.data,
            self.request.FILES or None)

    def clean_params(self):
        """Returns a validated form dict or an empty dict."""
        form = self.get_query_form()
        return form.cleaned_data if form.is_valid() else {}

from rest_framework.exceptions import ValidationError


class ModelSerializerMixin(object):
    """Provides generic model serializer classes to views."""
    model_serializer_class = None

    def get_serializer_class(self):
        if self.serializer_class:
            return self.serializer_class
        class DefaultSerializer(self.model_serializer_class):
            class Meta:
                model = self.queryset.model
        return DefaultSerializer


class QueryFormMixin(object):
    """Provides form based handling of GET or POST requests."""
    query_form_class = None

    def clean_params(self):
        """Returns a validated form dict from Request parameters."""
        form = self.query_form_class(
            self.request.query_params or self.request.data,
            self.request.FILES or None)
        if form.is_valid():
            return form.cleaned_data
        raise ValidationError(form.errors)

Throw ValidationError for invalid form, drop get_query_form()
Throw ValidationError for invalid form, drop get_query_form()

+ from rest_framework.exceptions import ValidationError
+ 
+ 
  class ModelSerializerMixin(object):
      """Provides generic model serializer classes to views."""
      model_serializer_class = None
  
      def get_serializer_class(self):
          if self.serializer_class:
              return self.serializer_class
          class DefaultSerializer(self.model_serializer_class):
              class Meta:
                  model = self.queryset.model
          return DefaultSerializer
  
  
  class QueryFormMixin(object):
      """Provides form based handling of GET or POST requests."""
      query_form_class = None
  
-     def get_query_form(self):
-         """Returns a bound form instance."""
+     def clean_params(self):
+         """Returns a validated form dict from Request parameters."""
-         return self.query_form_class(
+         form = self.query_form_class(
              self.request.query_params or self.request.data,
              self.request.FILES or None)
+         if form.is_valid():
+             return form.cleaned_data
+         raise ValidationError(form.errors)
  
-     def clean_params(self):
-         """Returns a validated form dict or an empty dict."""
-         form = self.get_query_form()
-         return form.cleaned_data if form.is_valid() else {}
- 
Throw ValidationError for invalid form, drop get_query_form()
## Code Before:
class ModelSerializerMixin(object):
    """Provides generic model serializer classes to views."""
    model_serializer_class = None

    def get_serializer_class(self):
        if self.serializer_class:
            return self.serializer_class
        class DefaultSerializer(self.model_serializer_class):
            class Meta:
                model = self.queryset.model
        return DefaultSerializer


class QueryFormMixin(object):
    """Provides form based handling of GET or POST requests."""
    query_form_class = None

    def get_query_form(self):
        """Returns a bound form instance."""
        return self.query_form_class(
            self.request.query_params or self.request.data,
            self.request.FILES or None)

    def clean_params(self):
        """Returns a validated form dict or an empty dict."""
        form = self.get_query_form()
        return form.cleaned_data if form.is_valid() else {}

## Instruction:
Throw ValidationError for invalid form, drop get_query_form()
## Code After:
from rest_framework.exceptions import ValidationError


class ModelSerializerMixin(object):
    """Provides generic model serializer classes to views."""
    model_serializer_class = None

    def get_serializer_class(self):
        if self.serializer_class:
            return self.serializer_class
        class DefaultSerializer(self.model_serializer_class):
            class Meta:
                model = self.queryset.model
        return DefaultSerializer


class QueryFormMixin(object):
    """Provides form based handling of GET or POST requests."""
    query_form_class = None

    def clean_params(self):
        """Returns a validated form dict from Request parameters."""
        form = self.query_form_class(
            self.request.query_params or self.request.data,
            self.request.FILES or None)
        if form.is_valid():
            return form.cleaned_data
        raise ValidationError(form.errors)
