| 1234567891011121314151617181920212223242526272829303132 |
- from django.db import models
- import datetime
- from django.core.validators import MaxValueValidator, MinValueValidator
- def current_year():
- return datetime.date.today().year
- def max_value_current_year(value):
- return MaxValueValidator(current_year())(value)
- class Autor(models.Model):
- nombre = models.CharField(max_length=200)
- biografia = models.TextField(blank=True, null=True)
- foto = models.ImageField(upload_to='autores/', blank=True, null=True) # Nuevo campo
- def __str__(self):
- return self.nombre
- class Libro(models.Model):
- titulo = models.CharField(max_length=200)
- autor = models.ForeignKey(Autor, on_delete=models.CASCADE)
- fecha_publicacion = models.PositiveBigIntegerField(default=current_year(), validators=[MinValueValidator(1984), max_value_current_year])
- descripcion = models.TextField(blank=True, null=True)
- archivo = models.FileField(upload_to='libros/')
- portada = models.ImageField(upload_to='portadas/', blank=True, null=True) # Nuevo campo
- def __str__(self):
- return self.titulo
|