From 8d0b35010835980c3d2886424486653c3b3ef14d Mon Sep 17 00:00:00 2001 From: Den_k0 Date: Mon, 9 Dec 2024 19:05:03 +0200 Subject: [PATCH 1/2] Solution --- author/serializers.py | 7 +++++-- author/urls.py | 15 +++++++++++++-- author/views.py | 7 +++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/author/serializers.py b/author/serializers.py index d286b95..79e0b03 100644 --- a/author/serializers.py +++ b/author/serializers.py @@ -1,6 +1,9 @@ from rest_framework import serializers +from author.models import Author + class AuthorSerializer(serializers.ModelSerializer): - # write your code here - pass + class Meta: + model = Author + fields = ["first_name", "last_name", "pseudonym", "age", "retired"] diff --git a/author/urls.py b/author/urls.py index fa856a3..af232fe 100644 --- a/author/urls.py +++ b/author/urls.py @@ -1,3 +1,14 @@ -# Create your urls here +from django.urls import path, include +from rest_framework import routers -urlpatterns = [] +from author.views import AuthorViewSet + + +router = routers.DefaultRouter() +router.register("manage", AuthorViewSet, basename="manage") + +urlpatterns = [ + path("", include(router.urls)) +] + +app_name = "author" diff --git a/author/views.py b/author/views.py index 608b89d..60e5d89 100644 --- a/author/views.py +++ b/author/views.py @@ -1,6 +1,9 @@ from rest_framework import viewsets +from author.models import Author +from author.serializers import AuthorSerializer + class AuthorViewSet(viewsets.ModelViewSet): - # write your code here - pass + queryset = Author.objects.all() + serializer_class = AuthorSerializer From 773f835c7efa97254de93a45fce26d3bf22cf2f3 Mon Sep 17 00:00:00 2001 From: Den_k0 Date: Mon, 9 Dec 2024 19:06:29 +0200 Subject: [PATCH 2/2] Solution fix: added migrations --- author/migrations/0001_initial.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 author/migrations/0001_initial.py diff --git a/author/migrations/0001_initial.py b/author/migrations/0001_initial.py new file mode 100644 index 0000000..3103f55 --- /dev/null +++ b/author/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 4.1 on 2024-12-09 16:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=64)), + ('last_name', models.CharField(max_length=64)), + ('pseudonym', models.CharField(blank=True, max_length=64, null=True)), + ('age', models.IntegerField()), + ('retired', models.BooleanField()), + ], + ), + ]