From 0e2cf47444872d9d66680f8e99771bba7ddc7f74 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Thu, 24 Oct 2024 12:34:37 +0000 Subject: [PATCH] =?UTF-8?q?C=C3=A1lculo=20autom=C3=A1tico=20de=20n=C3=BAme?= =?UTF-8?q?ro=20de=20pista?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReyMotaAppsDj/K8S/Makefile.local | 2 +- ReyMotaAppsDj/reymota/lyrics/forms.py | 2 +- ReyMotaAppsDj/reymota/lyrics/models.py | 2 +- ReyMotaAppsDj/reymota/lyrics/views.py | 16 +++++++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ReyMotaAppsDj/K8S/Makefile.local b/ReyMotaAppsDj/K8S/Makefile.local index b77f9a6..be4bd79 100644 --- a/ReyMotaAppsDj/K8S/Makefile.local +++ b/ReyMotaAppsDj/K8S/Makefile.local @@ -2,7 +2,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') export REGISTRY=localhost:30500 #export REGISTRY=registry.reymota.es -export IMG_VERSION = 0.55 +export IMG_VERSION = 0.60 export IMG_NGINX_VERSION = 1.0 # limpia todo diff --git a/ReyMotaAppsDj/reymota/lyrics/forms.py b/ReyMotaAppsDj/reymota/lyrics/forms.py index bda5204..9e17add 100644 --- a/ReyMotaAppsDj/reymota/lyrics/forms.py +++ b/ReyMotaAppsDj/reymota/lyrics/forms.py @@ -30,7 +30,7 @@ class AlbumForm(forms.ModelForm): class SongForm(forms.ModelForm): class Meta: model = Song - fields = ['title', 'artist', 'album', 'year', 'pista', 'lyrics'] + fields = ['title', 'artist', 'album', 'year', 'lyrics'] artist = forms.ModelChoiceField( queryset=Artista.objects.all(), diff --git a/ReyMotaAppsDj/reymota/lyrics/models.py b/ReyMotaAppsDj/reymota/lyrics/models.py index 5233f83..95a7d57 100644 --- a/ReyMotaAppsDj/reymota/lyrics/models.py +++ b/ReyMotaAppsDj/reymota/lyrics/models.py @@ -33,7 +33,7 @@ class Album(models.Model): class Song(models.Model): title = models.CharField(max_length=200) artist = models.ForeignKey(Artista, on_delete=models.CASCADE) - album = models.ForeignKey(Album, on_delete=models.CASCADE) + album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name='song') year = models.DecimalField(max_digits=4, decimal_places=0, blank=False, null=False) lyrics = models.TextField() pista = models.DecimalField(max_digits=5, decimal_places=0, blank=True, null=True) diff --git a/ReyMotaAppsDj/reymota/lyrics/views.py b/ReyMotaAppsDj/reymota/lyrics/views.py index c604454..984c13e 100644 --- a/ReyMotaAppsDj/reymota/lyrics/views.py +++ b/ReyMotaAppsDj/reymota/lyrics/views.py @@ -5,6 +5,9 @@ from django.contrib.auth.decorators import login_required from .models import Artista, Album, Song from .forms import ArtistaForm, AlbumForm, SongForm +import logging +logger = logging.getLogger(__name__) + @login_required def principal(request): @@ -141,7 +144,18 @@ def nuevo_song(request): if request.method == 'POST': form = SongForm(request.POST, request.FILES) if form.is_valid(): - form.save() + album = form.cleaned_data['album'] + + song_count = album.song.count() + + nueva_cancion = form.save(commit=False) + + nueva_cancion.pista = song_count + 1 + + nueva_cancion.save() + + logger.info("Canción creada %s", nueva_cancion.title) + return redirect('lyrics:lista_songs') else: form = SongForm()