|
|
from django.db import models
|
|
|
import datetime
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
|
def current_year():
|
|
|
return datetime.date.today().year
|
|
|
|
|
|
|
|
|
def max_value_current_year(value):
|
|
|
return MaxValueValidator(current_year())(value)
|
|
|
|
|
|
|
|
|
class Artista(models.Model):
|
|
|
nombre = models.CharField(max_length=200)
|
|
|
biografia = models.TextField(blank=True, null=True)
|
|
|
foto = models.ImageField(upload_to='artistas/', blank=True, null=True) # Nuevo campo
|
|
|
|
|
|
def __str__(self):
|
|
|
return self.nombre
|
|
|
|
|
|
|
|
|
class Album(models.Model):
|
|
|
name = models.CharField(max_length=200)
|
|
|
artist = models.ForeignKey(Artista, on_delete=models.CASCADE)
|
|
|
year = models.PositiveBigIntegerField(default=current_year(), validators=[MinValueValidator(1984), max_value_current_year])
|
|
|
cover_image = models.ImageField(upload_to='cover_image/', blank=True, null=True) # Nuevo campo
|
|
|
|
|
|
def __str__(self):
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
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)
|
|
|
year = models.PositiveBigIntegerField(default=current_year(), validators=[MinValueValidator(1984), max_value_current_year])
|
|
|
lyrics = models.CharField(max_length=1000)
|
|
|
pista = models.DecimalField(max_digits=5, decimal_places=0, blank=True, null=True)
|
|
|
|
|
|
def __str__(self):
|
|
|
return self.title
|
|
|
|