From 98275c6d23962937ef6745c70dba27fc0e8e01e5 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Thu, 20 Feb 2025 16:29:06 +0100 Subject: [PATCH] api buscando por nombre de artista y de album --- ReyMotaAppsDj/K8S/Makefile | 2 +- .../lyrics/management/commands/importar_albumes.py | 6 +++--- .../lyrics/management/commands/importar_canciones.py | 8 ++++---- ReyMotaAppsDj/reymota/lyrics/serializers.py | 9 +++++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ReyMotaAppsDj/K8S/Makefile b/ReyMotaAppsDj/K8S/Makefile index 5b2b31a..9faed53 100644 --- a/ReyMotaAppsDj/K8S/Makefile +++ b/ReyMotaAppsDj/K8S/Makefile @@ -1,7 +1,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') #export REGISTRY=registry.cube.local export REGISTRY=registry.reymota.es -export IMG_VERSION = 0.51 +export IMG_VERSION = 0.52 export IMG_NGINX_VERSION = 1.0 # limpia todo diff --git a/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_albumes.py b/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_albumes.py index e748e15..1abb4cb 100644 --- a/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_albumes.py +++ b/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_albumes.py @@ -26,10 +26,10 @@ class Command(BaseCommand): albumes_creados = 0 for album_data in datos: try: - artista = Artista.objects.get(id=album_data["artist"]) + artista = Artista.objects.get(nombre=album_data["artista_nombre"]) creado = Album.objects.create( - artist_id=artista.id, + artist=artista, name=album_data['name'], year=album_data['year'], cover_image=album_data['cover_image'], @@ -38,7 +38,7 @@ class Command(BaseCommand): albumes_creados += 1 except Artista.DoesNotExist: - self.stderr.write(self.style.ERROR(f"Artista '{album_data['artista']}' no encontrado.")) + self.stderr.write(self.style.ERROR(f"Artista '{album_data['artista_nombre']}' no encontrado.")) self.stdout.write(self.style.SUCCESS(f'Se importaron {albumes_creados} albumes correctamente.')) diff --git a/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_canciones.py b/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_canciones.py index 7856e40..27e434c 100644 --- a/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_canciones.py +++ b/ReyMotaAppsDj/reymota/lyrics/management/commands/importar_canciones.py @@ -26,13 +26,13 @@ class Command(BaseCommand): canciones_creados = 0 for cancion_data in datos: try: - album = Album.objects.get(id=cancion_data["album"]) - artista = Artista.objects.get(id=cancion_data["artist"]) + album = Album.objects.get(name=cancion_data["album_nombre"]) + artista = Artista.objects.get(nombre=cancion_data["artista_nombre"]) creado = Song.objects.create( - album_id=album.id, + album=album, + artist=artista, title=cancion_data['title'], - artist_id=artista.id, year=cancion_data['year'], lyrics=cancion_data['lyrics'], pista=cancion_data['pista'], diff --git a/ReyMotaAppsDj/reymota/lyrics/serializers.py b/ReyMotaAppsDj/reymota/lyrics/serializers.py index 5ba68cc..47d4398 100644 --- a/ReyMotaAppsDj/reymota/lyrics/serializers.py +++ b/ReyMotaAppsDj/reymota/lyrics/serializers.py @@ -9,12 +9,17 @@ class ArtistaSerializer(serializers.ModelSerializer): class AlbumSerializer(serializers.ModelSerializer): + artista_nombre = serializers.CharField(source='artist.nombre', read_only=True) + class Meta: model = Album - fields = '__all__' # Incluir todos los campos del modelo + fields = ['name', 'year', 'cover_image', 'artista_nombre'] class CancionSerializer(serializers.ModelSerializer): + artista_nombre = serializers.CharField(source='artist.nombre', read_only=True) + album_nombre = serializers.CharField(source='album.name', read_only=True) + class Meta: model = Song - fields = '__all__' # Incluir todos los campos del modelo + fields = ['title', 'year', 'lyrics', 'pista', 'artista_nombre', 'album_nombre']