добавил таблицу с участниками проекта

This commit is contained in:
Mike0001-droid 2024-06-02 13:39:30 +05:00
parent ff73a8e7d3
commit eb7043d3ad
3 changed files with 33 additions and 5 deletions

View File

@ -29,3 +29,17 @@ class Profile(models.Model):
# def create_auth_token(sender, instance=None, created=False, **kwargs):
# if created:
# Token.objects.create(user=instance)
class Team(models.Model):
name = models.CharField('Имя участника', max_length=50)
last_name = models.CharField('Фамилия участника', max_length=50)
position = models.CharField('Должность участинка', max_length=50)
img_person = models.ImageField('Изображение участника', blank=True, null=True, upload_to="team_images/")
def __str__(self):
return f"{self.last_name} {self.name} - {self.position}"
class Meta:
verbose_name = 'Команда'
verbose_name_plural = 'Команда'

View File

@ -1,6 +1,6 @@
from rest_framework import serializers, views, status
from rest_framework.response import Response
from .models import Profile
from .models import Profile, Team
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
@ -20,3 +20,10 @@ class ProfileSerializer(serializers.ModelSerializer):
def create(self, validated_data):
validated_data['likedSongs'] = []
return Profile.objects.create(**validated_data)
class TeamSerializer(serializers.ModelSerializer):
class Meta:
model = Team
fields = ('id', 'name', 'last_name', 'position', 'img_person')

View File

@ -1,6 +1,7 @@
from rest_framework.permissions import IsAuthenticated, AllowAny
from django.shortcuts import get_object_or_404
from django.db import transaction
from rest_framework.viewsets import ViewSet
from rest_framework import viewsets, status, views
from rest_framework.response import Response
from rest_framework.decorators import api_view, permission_classes, action
@ -8,8 +9,8 @@ from django.contrib.auth.models import User
from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework_simplejwt.exceptions import InvalidToken, AuthenticationFailed
from .models import Profile
from .serializers import ProfileSerializer
from .models import Profile, Team
from .serializers import ProfileSerializer, TeamSerializer
class ProfileViewSet(viewsets.ViewSet):
queryset = Profile.objects.all()
@ -60,4 +61,10 @@ class ProfileViewSet(viewsets.ViewSet):
serializer = ProfileSerializer(profile)
return Response(serializer.data['likedSongs'], status=status.HTTP_200_OK)
class TeamViewSet(ViewSet):
def list(self, request):
queryset = Team.objects.all()
serializer = TeamSerializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)