Added viewsets for shelves
This commit is contained in:
18
backend/apps/shelves/serializers.py
Normal file
18
backend/apps/shelves/serializers.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.shelves.models import Shelf
|
||||
from apps.user.serializers import UserSerializer
|
||||
from apps.user.models import User
|
||||
|
||||
class ShelfSerializer(serializers.ModelSerializer):
|
||||
user = UserSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Shelf
|
||||
fields = ["id", "name", "user"]
|
||||
read_only_fields = ["id"]
|
||||
|
||||
def create(self, validated_data):
|
||||
# Pobieramy user_id z tokena
|
||||
|
||||
return super().create(validated_data)
|
||||
9
backend/apps/shelves/urls.py
Normal file
9
backend/apps/shelves/urls.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from apps.shelves.views import ShelvesViewSet
|
||||
|
||||
urlpatterns = []
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("", viewset=ShelvesViewSet)
|
||||
urlpatterns += router.urls
|
||||
@@ -1,3 +1,9 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from apps.shelves.models import Shelf
|
||||
from apps.shelves.serializers import ShelfSerializer
|
||||
from rest_framework import viewsets
|
||||
|
||||
class ShelvesViewSet(viewsets.ModelViewSet):
|
||||
queryset = Shelf.objects.select_related("user")
|
||||
serializer_class = ShelfSerializer
|
||||
5
backend/apps/urls.py
Normal file
5
backend/apps/urls.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path("shelves", include("apps.shelves.urls"))
|
||||
]
|
||||
9
backend/apps/user/serializers.py
Normal file
9
backend/apps/user/serializers.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.user.models import User
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = '__all__'
|
||||
Reference in New Issue
Block a user