LORDCHANNEL2.0/Film/models.py

105 lines
3.9 KiB
Python
Raw Permalink Normal View History

2021-03-13 18:36:50 +00:00
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator,MaxValueValidator
from django.utils.text import slugify
from core.models import Profilo
from django.contrib.contenttypes.fields import GenericRelation
# Create your models here.
class GenereFilm(models.Model):
genere = models.CharField(max_length=120)
def __str__(self):
return self.genere
class Meta:
verbose_name = "Genere"
verbose_name_plural = "Generi"
def get_absolute_url(self):
return reverse('film-genere', kwargs={'genere': self.genere})
class Film(models.Model):
titolo = models.CharField(max_length=200)
descrizione = models.TextField()
genere = models.ManyToManyField(GenereFilm,blank=True)
qualità_video = models.CharField(max_length=20,null=True,blank=True)
età_consigliata = models.CharField(max_length=20,null=True,blank=True)
immagine_background = models.ImageField(null=True,blank=True)
immagine_poster = models.ImageField(null=True,blank=True)
LINGUE = [
('ITA', "Italiano"),
('SUB-ITA', "Sottotitolato In Italiano"),
]
lingua = models.CharField(max_length=12,choices=LINGUE,default="ITA")
voto = models.FloatField(validators=[MinValueValidator(1.0),MaxValueValidator(10.0)],null=True,blank=True)
creato_in_data = models.DateTimeField(auto_now_add=True,null=True,blank=True)
aggiornato_in_data = models.DateTimeField(auto_now=True)
slug = models.SlugField(unique=True,null=True,blank=True)
preferito = models.ManyToManyField(Profilo,related_name="preferiti",blank=True)
guarda_dopo = models.ManyToManyField(Profilo,related_name="watch_later",blank=True)
data_uscita = models.CharField(max_length=20,null=True,blank=True)
visualizzazioni = models.IntegerField(default=0)
durata = models.CharField(max_length=20,null=True,blank=True)
streaming_url = models.URLField(null=True,blank=True)
trailer = models.URLField(null=True,blank=True)
def __str__(self):
return self.titolo
class Meta:
verbose_name = "Film"
verbose_name_plural = "Film"
def save(self, *args, **kwargs):
self.slug = slugify(self.titolo)
super(Film,self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('film-detail', kwargs={'slug': self.slug})
class Commento(models.Model):
utente = models.ForeignKey(Profilo,on_delete=models.CASCADE,related_name="commenti_user")
commento = models.TextField()
data_commento = models.DateTimeField(auto_now_add=True)
media = models.ForeignKey(Film,on_delete=models.CASCADE,related_name="commenti_film")
class Meta:
verbose_name = "Commento"
verbose_name_plural = "Commenti"
def __str__(self):
return f"{self.utente.user} ha scritto un commento sul Film {self.media.titolo}"
class SegnalazioneFilm(models.Model):
LISTA_PROBLEMI_VIDEO = [
('Link Non Funzionante', 'Link Non Funzionante'),
('Video Pessima Qualitá', 'Video Pessima Qualitá'),
('Audio Mancante', 'Audio Mancante'),
('Film Incompleto', 'Film Incompleto'),
('Altro', 'Altro'),
]
problema_video = models.CharField(
max_length=50,
choices=LISTA_PROBLEMI_VIDEO,
default='Link Non Funzionante',
)
descrizione_problema = models.TextField()
film = models.ForeignKey(Film,on_delete=models.CASCADE,related_name="film_segnalato")
class Meta:
verbose_name = "Segnalazione"
verbose_name_plural = "Segnalazioni"
def __str__(self):
return f"Hanno Segnalato un Problema sul Film {self.film.titolo}"
class Immagini(models.Model):
film = models.ForeignKey(Film,on_delete=models.CASCADE,related_name="immagini_film")
immagini = models.ImageField(null=True,blank=True)
def __str__(self):
return f"Immagine del Film {self.film.titolo}"