diff --git a/lab-1/http.restbook b/lab-1/http.restbook new file mode 100644 index 0000000..6b42869 --- /dev/null +++ b/lab-1/http.restbook @@ -0,0 +1 @@ +[{"kind":2,"language":"rest-book","value":"GET http://localhost:8000/api/quiz/","outputs":[{"mime":"x-application/rest-book","value":{"status":200,"statusText":"OK","headers":{"Allow":"GET, HEAD, OPTIONS","Date":"Thu, 02 Apr 2026 11:20:40 GMT","Content-Type":"application/json","Content-Length":"37","Server":"nginx/1.29.7","X-Frame-Options":"DENY","Connection":"close"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","User-Agent":"axios/0.21.4"}},"request":{"method":"GET","httpVersion":"1.1","responseUrl":"http://localhost/api/quiz/","timeout":10000,"headers":{}},"data":{"quiz":"http://localhost/api/quiz/"}}},{"mime":"text/x-json","value":{"status":200,"statusText":"OK","headers":{"Allow":"GET, HEAD, OPTIONS","Date":"Thu, 02 Apr 2026 11:20:40 GMT","Content-Type":"application/json","Content-Length":"37","Server":"nginx/1.29.7","X-Frame-Options":"DENY","Connection":"close"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","User-Agent":"axios/0.21.4"}},"request":{"method":"GET","httpVersion":"1.1","responseUrl":"http://localhost/api/quiz/","timeout":10000,"headers":{}},"data":{"quiz":"http://localhost/api/quiz/"}}},{"mime":"text/html","value":"[object Object]"}]},{"kind":2,"language":"rest-book","value":"POST http://localhost:8000/api/quiz/\r\nContent-Type: application/json\r\n\r\n{\r\n \"title\": \"Название\",\r\n \"description\": \"Описание\",\r\n \"author\": \"Автор\",\r\n \"time_limit\": 40,\r\n \"is_published\": false\r\n}","outputs":[{"mime":"x-application/rest-book","value":{"status":405,"statusText":"Method Not Allowed","headers":{"Allow":"GET, HEAD, OPTIONS","Date":"Thu, 02 Apr 2026 11:20:56 GMT","Content-Type":"application/json","Content-Length":"55","Server":"nginx/1.29.7","X-Frame-Options":"DENY","Connection":"close"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Agent":"axios/0.21.4","Content-Length":120}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost/api/quiz/","timeout":10000,"headers":{"Content-Type":"application/json"},"data":{"title":"Название","description":"Описание","author":"Автор","time_limit":40,"is_published":false}},"data":{"detail":"Метод \"POST\" не разрешен."}}},{"mime":"text/x-json","value":{"status":405,"statusText":"Method Not Allowed","headers":{"Allow":"GET, HEAD, OPTIONS","Date":"Thu, 02 Apr 2026 11:20:56 GMT","Content-Type":"application/json","Content-Length":"55","Server":"nginx/1.29.7","X-Frame-Options":"DENY","Connection":"close"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Agent":"axios/0.21.4","Content-Length":120}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost/api/quiz/","timeout":10000,"headers":{"Content-Type":"application/json"},"data":{"title":"Название","description":"Описание","author":"Автор","time_limit":40,"is_published":false}},"data":{"detail":"Метод \"POST\" не разрешен."}}},{"mime":"text/html","value":"[object Object]"}]},{"kind":2,"language":"rest-book","value":"GET http://localhost:8000/api/quiz/8/","outputs":[{"mime":"application/vnd.code.notebook.error","value":{"name":"Error","message":"{}"}}]},{"kind":2,"language":"rest-book","value":"PUT http://localhost:8000/api/quiz/8/\r\nContent-Type: application/json\r\n\r\n{\r\n \"title\": \"Новое Название\",\r\n \"description\": \"Новое Описание\",\r\n \"author\": \"Новый Автор\",\r\n \"time_limit\": 40,\r\n \"is_published\": true\r\n}","outputs":[{"mime":"application/vnd.code.notebook.error","value":{"name":"Error","message":"{}"}}]},{"kind":2,"language":"rest-book","value":"DELETE http://localhost:8000/api/quiz/8/","outputs":[{"mime":"application/vnd.code.notebook.error","value":{"name":"Error","message":"{}"}}]}] \ No newline at end of file diff --git a/lab-1/quiz/admin.py b/lab-1/quiz/admin.py new file mode 100644 index 0000000..3847636 --- /dev/null +++ b/lab-1/quiz/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import Quiz + +admin.site.register(Quiz) diff --git a/lab-1/quiz/gentestdata.py b/lab-1/quiz/gentestdata.py new file mode 100644 index 0000000..cd9d892 --- /dev/null +++ b/lab-1/quiz/gentestdata.py @@ -0,0 +1,18 @@ +import random +from .models import Quiz +from django.db import transaction +from faker import Faker + +fk = Faker() + +def gentestdata(): + with transaction.atomic(): + for i in range(100): + new_quiz = Quiz() + new_quiz.title = fk.sentence(nb_words=4) + new_quiz.description = fk.paragraph() + new_quiz.author = fk.name() + new_quiz.time_limit = random.randint(5, 60) + new_quiz.is_published = random.random() > 0.5 + new_quiz.save() + print('Сделана генерация') diff --git a/lab-1/quiz/serializers.py b/lab-1/quiz/serializers.py new file mode 100644 index 0000000..08dac96 --- /dev/null +++ b/lab-1/quiz/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from .models import Quiz + +class QuizSerializer(serializers.ModelSerializer): + class Meta: + model = Quiz + fields = '__all__' \ No newline at end of file diff --git a/lab-1/quiz/tests.py b/lab-1/quiz/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/lab-1/quiz/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/lab-1/quiz/views.py b/lab-1/quiz/views.py new file mode 100644 index 0000000..a7c4b53 --- /dev/null +++ b/lab-1/quiz/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render + +from rest_framework import viewsets +from .models import Quiz +from .serializers import QuizSerializer + +class QuizViewSet(viewsets.ModelViewSet): + queryset = Quiz.objects.all() + serializer_class = QuizSerializer