diff --git a/authserver/authserver/api/models.py b/authserver/authserver/api/models.py index 884e995..b796b25 100644 --- a/authserver/authserver/api/models.py +++ b/authserver/authserver/api/models.py @@ -3,7 +3,7 @@ from django.db import models class Category(models.Model): name = models.CharField(max_length=32) - slug = models.CharField(max_length=32) + slug = models.CharField(max_length=32, unique=True) info = models.TextField(max_length=1024, blank=True) photo = models.ImageField() @@ -13,6 +13,7 @@ class Category(models.Model): class Tool(models.Model): category = models.ForeignKey(Category, related_name='tools', on_delete=models.PROTECT) name = models.CharField(max_length=32) + slug = models.CharField(max_length=32, unique=True) info = models.TextField(max_length=1024, blank=True) wiki_id = models.IntegerField() photo = models.ImageField() diff --git a/authserver/authserver/api/serializers.py b/authserver/authserver/api/serializers.py index 351b007..aad5707 100644 --- a/authserver/authserver/api/serializers.py +++ b/authserver/authserver/api/serializers.py @@ -13,10 +13,17 @@ class ToolSerializer(serializers.ModelSerializer): model = models.Tool fields = '__all__' +class ToolDataSerializer(serializers.ModelSerializer): + tools = ToolSerializer(many=True) + + class Meta: + model = models.Category + fields = '__all__' + class ProfileSerializer(serializers.ModelSerializer): class Meta: model = models.Profile - fields = ('lockout_admin', 'authorized_tools') + fields = '__all__' class UserSerializer(serializers.ModelSerializer): profile = ProfileSerializer(read_only=True) diff --git a/authserver/authserver/api/views.py b/authserver/authserver/api/views.py index a274cf9..bd12773 100644 --- a/authserver/authserver/api/views.py +++ b/authserver/authserver/api/views.py @@ -1,5 +1,5 @@ from django.contrib.auth.models import User -from rest_framework import viewsets +from rest_framework import viewsets, permissions from . import models, serializers @@ -11,6 +11,10 @@ class ToolViewSet(viewsets.ModelViewSet): queryset = models.Tool.objects.all().order_by('id') serializer_class = serializers.ToolSerializer +class ToolDataViewSet(viewsets.ReadOnlyModelViewSet): + queryset = models.Category.objects.all().order_by('id') + serializer_class = serializers.ToolDataSerializer + class ProfileViewSet(viewsets.ModelViewSet): queryset = models.Profile.objects.all().order_by('-user__date_joined') serializer_class = serializers.ProfileSerializer diff --git a/authserver/authserver/urls.py b/authserver/authserver/urls.py index 500f842..acbb044 100644 --- a/authserver/authserver/urls.py +++ b/authserver/authserver/urls.py @@ -25,6 +25,7 @@ from .api import views router = routers.DefaultRouter() router.register(r'tool', views.ToolViewSet, 'tool') router.register(r'category', views.CategoryViewSet, 'category') +router.register(r'tooldata', views.ToolDataViewSet, 'tooldata') router.register(r'profile', views.ProfileViewSet, 'profile') router.register(r'user', views.UserViewSet, 'user')