Created
March 17, 2018 04:40
-
-
Save biancarosa/6fe135f4165affa837e9e99237f09a41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# urls.py | |
from django.conf.urls import url, include | |
from rest_framework import routers, viewsets | |
from dashboard_api.views.user import UserViewSet | |
router = routers.DefaultRouter() | |
router.register(r'users', UserViewSet) | |
urlpatterns = [ | |
url(r'^', include(router.urls)), | |
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) | |
] | |
# serializers/user.py | |
from django.contrib.auth.models import User | |
from rest_framework import serializers | |
class UserSerializer(serializers.HyperlinkedModelSerializer): | |
class Meta: | |
model = User | |
fields = ('email', 'first_name', 'last_name', 'username', 'password') | |
# views/user.py | |
from django.contrib.auth.models import User | |
from rest_framework import viewsets | |
from dashboard_api.serializers.user import UserSerializer | |
class UserViewSet(viewsets.ModelViewSet): | |
queryset = User.objects.all() | |
serializer_class = UserSerializer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment