diff --git a/.flake8 b/.flake8 index b5381af..e8114cc 100644 --- a/.flake8 +++ b/.flake8 @@ -7,4 +7,4 @@ select = B,C,E,F,W,T4,B9,Q0,N8,VNE exclude = **migrations venv - tests \ No newline at end of file + tests diff --git a/author/migrations/0001_initial.py b/author/migrations/0001_initial.py new file mode 100644 index 0000000..216a0f8 --- /dev/null +++ b/author/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 4.1 on 2024-12-02 21:20 + +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()), + ], + ), + ] diff --git a/author/models.py b/author/models.py index 4b1ae90..070c36d 100644 --- a/author/models.py +++ b/author/models.py @@ -7,3 +7,6 @@ class Author(models.Model): pseudonym = models.CharField(max_length=64, null=True, blank=True) age = models.IntegerField() retired = models.BooleanField() + + def __str__(self): + return f"{self.first_name} {self.last_name}" diff --git a/author/serializers.py b/author/serializers.py index d286b95..e7856f7 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 = "__all__" diff --git a/author/urls.py b/author/urls.py index fa856a3..c486d79 100644 --- a/author/urls.py +++ b/author/urls.py @@ -1,3 +1,11 @@ -# Create your urls here +from django.urls import path, include +from rest_framework import routers -urlpatterns = [] +from author.views import AuthorViewSet + +app_name = "author" + +router = routers.DefaultRouter() +router.register("authors", AuthorViewSet, basename="manage") + +urlpatterns = [path("", include(router.urls)), ] 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