Django Rest Model serializers and model inheritance


I write custom model of user in my app. Application components are:

  • Django 1.8
  • Django REST framework 3.2.4
  • Django-allauth 0.23.0
  • Django-rest-auth 0.5.

Code of user model you can see When I go to Django-rest-auth registration endpoint I see this error:

ValueError at /rest-auth/registration/
Cannot use ModelSerializer with Abstract Models.

This is settings are relating with Django-rest-auth:


How can I solve this problem ?

to the best of my knowledge, DRF does not currently support the use of ModelSerializer with Abstract Models, however, you can use Serializer.

A simple implementation would be something (not tested) like:

class MyUserSerializer(serializers.Serializer):
    email = serializers.EmailField()
    is_active = serializers.BooleanField(default=False)
    is_admin = serializers.BooleanField(default=False)
    student  = serializers.BooleanField(default=True)

Then in your view, you can manually save. Something like...

class MyUserView(APIView):
    def post(self, request):
        serializer = MyUserSerializer(data=request.DATA)
        if serializer.is_valid():
            return Response(status=status.HTTP_201_CREATED)
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Also, for the discussion about whether or not to include this use of ModelSerializer checkout and

Hope this helps!