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:
0
InvenTree/users/__init__.py
Normal file
0
InvenTree/users/__init__.py
Normal file
6
InvenTree/users/admin.py
Normal file
6
InvenTree/users/admin.py
Normal 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
8
InvenTree/users/apps.py
Normal file
@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
name = 'users'
|
6
InvenTree/users/models.py
Normal file
6
InvenTree/users/models.py
Normal file
@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
15
InvenTree/users/serializers.py
Normal file
15
InvenTree/users/serializers.py
Normal 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
6
InvenTree/users/tests.py
Normal 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
9
InvenTree/users/urls.py
Normal 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
17
InvenTree/users/views.py
Normal 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,)
|
Reference in New Issue
Block a user