| 12345678910111213141516171819202122232425262728293031323334 |
- """
- @author: olinox, 2021
- """
- from django.conf import settings
- from django.urls import path, include
- from django.conf.urls.static import static
- from rest_framework import routers, serializers, viewsets
- from . import views
- # Serializers define the API representation.
- class UserSerializer(serializers.HyperlinkedModelSerializer):
- class Meta:
- model = User
- fields = ['url', 'username', 'email', 'is_staff']
- # ViewSets define the view behavior.
- class UserViewSet(viewsets.ModelViewSet):
- queryset = User.objects.all()
- serializer_class = UserSerializer
- # Routers provide an easy way of automatically determining the URL conf.
- router = routers.DefaultRouter()
- router.register(r'users', UserViewSet)
- urlpatterns = [
- path('', views.index, name='index'),
- path('api-auth/', include('rest_framework.urls'))
- ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|