Added some logic
This commit is contained in:
0
backend/apps/authors/__init__.py
Normal file
0
backend/apps/authors/__init__.py
Normal file
3
backend/apps/authors/admin.py
Normal file
3
backend/apps/authors/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
backend/apps/authors/apps.py
Normal file
5
backend/apps/authors/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AuthorsConfig(AppConfig):
|
||||
name = 'apps.authors'
|
||||
0
backend/apps/authors/migrations/__init__.py
Normal file
0
backend/apps/authors/migrations/__init__.py
Normal file
6
backend/apps/authors/models.py
Normal file
6
backend/apps/authors/models.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.db import models
|
||||
from apps.user.models import User
|
||||
|
||||
class Author(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Authors")
|
||||
name = models.CharField(max_length=255)
|
||||
0
backend/apps/authors/serializers.py
Normal file
0
backend/apps/authors/serializers.py
Normal file
3
backend/apps/authors/tests.py
Normal file
3
backend/apps/authors/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
9
backend/apps/authors/urls.py
Normal file
9
backend/apps/authors/urls.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from apps.authors.views import AuthorsViewSet
|
||||
|
||||
urlpatterns = []
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("", viewset=AuthorsViewSet)
|
||||
urlpatterns += router.urls
|
||||
20
backend/apps/authors/views.py
Normal file
20
backend/apps/authors/views.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from rest_framework import viewsets
|
||||
|
||||
from apps.authors.models import Author
|
||||
from apps.authors.serializers import AuthorSerializer
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
|
||||
class AuthorsViewSet(viewsets.ModelViewSet):
|
||||
queryset = Author.objects.select_related("shelf")
|
||||
serializer_class = AuthorSerializer
|
||||
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_queryset(self):
|
||||
return self.queryset.filter(
|
||||
shelf__user_id=self.request.user.pk
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user