Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
xtsvi committed Nov 6, 2024
1 parent 7155dc0 commit b926406
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 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-06 13:34

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()),
],
),
]
14 changes: 12 additions & 2 deletions author/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from rest_framework import serializers

from author.models import Author


class AuthorSerializer(serializers.ModelSerializer):
# write your code here
pass
class Meta:
model = Author
fields = (
"id",
"first_name",
"last_name",
"pseudonym",
"age",
"retired"
)
2 changes: 1 addition & 1 deletion author/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from author.models import Author
from author.serializers import AuthorSerializer

AUTHORS_URL = reverse("author:manage-list")
AUTHORS_URL = reverse("author:author-list")


class AuthorApiTests(TestCase):
Expand Down
14 changes: 12 additions & 2 deletions author/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 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)

urlpatterns = [
path("", include(router.urls))
]
7 changes: 5 additions & 2 deletions author/views.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b926406

Please sign in to comment.