4

I'm setting up something similar to the Django Rest Framework quickstart example, but with custom django-authtools User model.

api.py:

router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)

urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]

serializers.py:

class GroupSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:

        model = Group
        fields = ('url', 'name')


class UserSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = User
        fields = ('name', 'email', 'groups')

views.py:

class UserViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows users to be viewed or edited.
    """
    queryset = User.objects.all()
    serializer_class = UserSerializer


class GroupViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows users to be viewed or edited.
    """
    queryset = Group.objects.all()
    serializer_class = GroupSerializer

I'm running Django 1.8.5. Is there something extra I have to configure to work with the custom user model, or I have I just missed something silly?

3
  • What's your DRF version? Commented Nov 3, 2015 at 10:01
  • DRF version is 3.2.5 Commented Nov 3, 2015 at 20:30
  • 1
    I had similar problem and for me works this method Commented Nov 16, 2015 at 15:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.