Создан API, добавлен URL
This commit is contained in:
1 parent
f66ac380c1
commit
2e0a85c93c
5 files changed
+29
-5
No files matched your search
+1
-1
@@ -4,4 +4,4 @@ from django.apps import AppConfig
|
||||
class SafetyConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'safety'
|
||||
verbose_name = 'Безопасность'
|
||||
verbose_name = 'Раздел Безопасность'
|
||||
@@ -13,8 +13,8 @@ class SafetyFile(models.Model):
|
||||
|
||||
class Meta:
|
||||
|
||||
verbose_name = 'Раздел безопасности'
|
||||
verbose_name_plural = 'Раздел безопасности'
|
||||
verbose_name = 'Документы раздела безопасности'
|
||||
verbose_name_plural = 'Документы раздела безопасности'
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name_chapter)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
from rest_framework import serializers
|
||||
from .models import *
|
||||
|
||||
class SafetyFileSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = SafetyFile
|
||||
fields = '__all__'
|
||||
+7
-1
@@ -1,2 +1,8 @@
|
||||
from django.urls import path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('files/', SafetyFileAPIView.as_view(), name='safety_files')
|
||||
]
|
||||
+12
-1
@@ -1,4 +1,15 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework.views import ListAPIView
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from .serializers import *
|
||||
from .models import *
|
||||
# Create your views here.
|
||||
|
||||
class SafetyFileAPIView(APIView):
|
||||
def get(self, request):
|
||||
|
||||
all_file = SafetyFile.objects.all()
|
||||
serializer_for_file = SafetyFileSerializer(instance=all_file, many=True)
|
||||
# print(serializer_for_file)
|
||||
|
||||
return Response({'Файлы': serializer_for_file})
|
||||
Reference in new issue
Block a user