2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 20:15:44 +00:00

Added User API and serializer

This commit is contained in:
Oliver Walters
2017-04-20 22:40:59 +10:00
parent 92cbd43f0f
commit 4777b02080
12 changed files with 79 additions and 2 deletions

View File

6
InvenTree/users/admin.py Normal file
View File

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.

8
InvenTree/users/apps.py Normal file
View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'

View File

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
# Create your models here.

View File

@ -0,0 +1,15 @@
from rest_framework import serializers
from django.contrib.auth.models import User
class UserSerializer(serializers.HyperlinkedModelSerializer):
""" Serializer for a User
"""
class Meta:
model = User
fields = ('username',
'first_name',
'last_name',
'email',)

6
InvenTree/users/tests.py Normal file
View File

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.

9
InvenTree/users/urls.py Normal file
View File

@ -0,0 +1,9 @@
from django.conf.urls import url, include
from . import views
user_urls = [
url(r'^(?P<pk>[0-9]+)/?$', views.UserDetail.as_view(), name='user-detail'),
url(r'^$', views.UserList.as_view()),
]

17
InvenTree/users/views.py Normal file
View File

@ -0,0 +1,17 @@
from rest_framework import generics, permissions, response
from django.contrib.auth.models import User
from .serializers import UserSerializer
class UserDetail(generics.RetrieveAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class UserList(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)