изменил конфиги для локалки
This commit is contained in:
parent
73e47e3cbc
commit
834c8b9e79
|
|
@ -40,5 +40,5 @@ class FavoriteSong(models.Model):
|
|||
|
||||
class PlayList(models.Model):
|
||||
name = models.CharField('Название плейлиста', max_length=50)
|
||||
song = models.ManyToManyField(Song)
|
||||
song = models.ManyToManyField(Song, blank=True, null=True)
|
||||
user = models.ForeignKey(MyUser, verbose_name='Пользователь', on_delete=models.CASCADE, blank=True, null=True)
|
||||
|
|
@ -53,3 +53,20 @@ class DeleteSongSchema(AutoSchema):
|
|||
schema=coreschema.String(description='ID трека с Азуры')
|
||||
),
|
||||
]
|
||||
|
||||
class PlayListSchema(AutoSchema):
|
||||
def get_serializer_fields(self, path, method):
|
||||
return [
|
||||
coreapi.Field(
|
||||
name='playlist_id',
|
||||
location='form',
|
||||
required=False,
|
||||
schema=coreschema.Integer(description='ID плейлиста')
|
||||
),
|
||||
coreapi.Field(
|
||||
name='songs_id',
|
||||
location='form',
|
||||
required=False,
|
||||
schema=coreschema.Array(description='ID треков')
|
||||
),
|
||||
]
|
||||
|
|
@ -5,11 +5,11 @@ from rest_framework.decorators import action
|
|||
from rest_framework import status
|
||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||
from django.shortcuts import get_object_or_404, get_list_or_404
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||
import requests
|
||||
from django.http import HttpResponse
|
||||
|
||||
from .schemas import SongSchema, DeleteSongSchema
|
||||
from .schemas import SongSchema, DeleteSongSchema, PlayListSchema
|
||||
from .models import Song, FavoriteSong, PlayList
|
||||
from .serializers import SongSerializer, FavoriteSongSerializer, PlayListSerializer
|
||||
|
||||
|
|
@ -31,8 +31,6 @@ class PlayListViewSet(GenericViewSet):
|
|||
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
|
||||
|
||||
class SongViewSet(GenericViewSet):
|
||||
queryset = Song.objects.all()
|
||||
serializer_class = SongSerializer
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
from .local import *
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
from .production import *
|
||||
from .local import *
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,21 @@
|
|||
import sys
|
||||
from .base import *
|
||||
|
||||
DEBUG = True
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'] = ('rest_framework.permissions.AllowAny',)
|
||||
|
||||
if len(sys.argv) >= 2 and not sys.argv[0].endswith('manage.py'):
|
||||
from conf.sentry import sentry_start, SENTRY_CONFIG
|
||||
|
||||
SENTRY_CONFIG['environment'] = 'local'
|
||||
sentry_start(SENTRY_CONFIG)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,13 +1,9 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from rest_framework.authtoken.admin import TokenAdmin
|
||||
from .models import Team
|
||||
|
||||
|
||||
|
||||
TokenAdmin.raw_id_fields = ['user']
|
||||
|
||||
|
||||
@admin.register(Team)
|
||||
class TeamAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'name', 'last_name', 'position', 'img_person')
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -2,34 +2,6 @@ from django.contrib.auth.models import User
|
|||
from django.db import models
|
||||
from django.db.models import JSONField
|
||||
|
||||
""" class Profile(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
|
||||
likedSongs = JSONField(blank=True, null=True)
|
||||
"""
|
||||
|
||||
# likedSongs = models.ManyToManyField(Song)
|
||||
# likedSongs = models.TextField()
|
||||
# podcasts = models.ManyToManyField(Podcast)
|
||||
# playlists = models.ManyToManyField(Playlist)
|
||||
|
||||
|
||||
# #JWT
|
||||
# from django.contrib.auth.models import User
|
||||
# from rest_framework.authtoken.models import Token
|
||||
|
||||
# for user in User.objects.all():
|
||||
# Token.objects.get_or_create(user=user)
|
||||
|
||||
# from django.conf import settings
|
||||
# from django.db.models.signals import post_save
|
||||
# from django.dispatch import receiver
|
||||
|
||||
# @receiver(post_save, sender=settings.AUTH_USER_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)
|
||||
|
|
|
|||
|
|
@ -2,25 +2,6 @@ from rest_framework import serializers, views, status
|
|||
from rest_framework.response import Response
|
||||
from .models import Team
|
||||
|
||||
""" class ProfileSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Profile
|
||||
fields = ['user', 'likedSongs']
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
new_song = validated_data.get('likedSongs')
|
||||
if new_song:
|
||||
current_songs = instance.likedSongs or []
|
||||
# Check if the song ID already exists in the current songs
|
||||
if not any(song['id'] == new_song['id'] for song in current_songs):
|
||||
current_songs.append(new_song)
|
||||
instance.likedSongs = current_songs
|
||||
instance.save()
|
||||
return instance
|
||||
def create(self, validated_data):
|
||||
validated_data['likedSongs'] = []
|
||||
return Profile.objects.create(**validated_data) """
|
||||
|
||||
class TeamSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Team
|
||||
|
|
|
|||
|
|
@ -8,61 +8,9 @@ from rest_framework.decorators import api_view, permission_classes, action
|
|||
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, Team
|
||||
from .serializers import ProfileSerializer, TeamSerializer """
|
||||
|
||||
from .models import Team
|
||||
from .serializers import TeamSerializer
|
||||
|
||||
""" class ProfileViewSet(viewsets.ViewSet):
|
||||
queryset = Profile.objects.all()
|
||||
def list(self, request):
|
||||
queryset = Profile.objects.all()
|
||||
serializer = ProfileSerializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def AddSong(self, request):
|
||||
if request.method == 'POST':
|
||||
user = request.user.pk
|
||||
new_song = request.data.get('new_song') # new_song should be a dict
|
||||
profile = get_object_or_404(Profile, user=user)
|
||||
serializer = ProfileSerializer(profile, data={'likedSongs': new_song}, partial=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def DeleteSong(self, request):
|
||||
user = request.user.pk
|
||||
song_id = request.data.get('id') # Assuming each song has a unique 'id' field
|
||||
if not song_id:
|
||||
return Response({'error': 'Song ID is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
profile = get_object_or_404(Profile, user=user)
|
||||
if profile.likedSongs:
|
||||
# Filter out the song with the given ID
|
||||
updated_songs = [song for song in profile.likedSongs if song.get('id') != song_id]
|
||||
profile.likedSongs = updated_songs
|
||||
profile.save()
|
||||
return Response({'message': 'Song deleted'}, status=status.HTTP_204_NO_CONTENT)
|
||||
else:
|
||||
return Response({'error': 'No songs to delete'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
@action(
|
||||
detail=False,
|
||||
methods=['get'],
|
||||
url_path='getlikedsongs/',
|
||||
url_name='liked_songs',
|
||||
)
|
||||
def GetLikedSongs(request):
|
||||
if request.method == 'GET':
|
||||
user = request.user.pk
|
||||
profile = get_object_or_404(Profile, user=user)
|
||||
serializer = ProfileSerializer(profile)
|
||||
return Response(serializer.data['likedSongs'], status=status.HTTP_200_OK) """
|
||||
|
||||
class TeamViewSet(ViewSet):
|
||||
def list(self, request):
|
||||
|
|
|
|||
Loading…
Reference in New Issue