Add tooldata API read-only route
This commit is contained in:
parent
ac9aeb909a
commit
e1c776698e
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user