Skip to content

Commit

Permalink
"solution"
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenmarkotskyi committed Nov 30, 2024
1 parent 7155dc0 commit 45c5d96
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
25 changes: 25 additions & 0 deletions author/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1 on 2024-11-30 14:24

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()),
],
),
]
10 changes: 8 additions & 2 deletions author/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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"
]
25 changes: 23 additions & 2 deletions author/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# Create your urls here
from rest_framework import routers
from django.urls import path, include
from author.views import AuthorViewSet

urlpatterns = []
app_name = "author"

author_list = AuthorViewSet.as_view(
actions={
"get": "list",
"post": "create"
}
)
author_detail = AuthorViewSet.as_view(
actions={
"get": "retrieve",
"put": "update",
"patch": "partial_update",
"delete": "destroy"
}
)
urlpatterns = [
path("authors/", author_list, name="manage-list"),
path("authors/<int:pk>/", author_detail, name="manage-detail"),
]
6 changes: 5 additions & 1 deletion author/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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
2 changes: 1 addition & 1 deletion author_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

urlpatterns = [
path("admin/", admin.site.urls),
path("api/", include("author.urls", namespace="author")),
path("api/author/", include("author.urls", namespace="author")),
]

0 comments on commit 45c5d96

Please sign in to comment.