Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Author CRUD Implementation #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-12-02 03:47

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()),
],
),
]
3 changes: 3 additions & 0 deletions author/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> str:
return f"{self.first_name} {self.last_name} ({self.pseudonym})"
6 changes: 4 additions & 2 deletions author/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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__"
13 changes: 11 additions & 2 deletions author/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Create your urls here
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import AuthorViewSet

urlpatterns = []
app_name = "author"

router = DefaultRouter()
router.register("manage", AuthorViewSet, basename="manage")

urlpatterns = [
path("", include(router.urls)),
]
10 changes: 6 additions & 4 deletions author/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from rest_framework import viewsets
from rest_framework.viewsets import ModelViewSet
from author.models import Author
from author.serializers import AuthorSerializer


class AuthorViewSet(viewsets.ModelViewSet):
# write your code here
pass
class AuthorViewSet(ModelViewSet):
queryset = Author.objects.all()
serializer_class = AuthorSerializer