Advertisement
horozov86

2.Media

Nov 23rd, 2023
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. class BaseMedia(models.Model):
  2.     title = models.CharField(max_length=100)
  3.     description = models.TextField()
  4.     genre = models.CharField(max_length=50)
  5.     created_at = models.DateTimeField(auto_now_add=True)
  6.    
  7.     class Meta:
  8.         abstract= True
  9.         ordering = ["-created_at", "title"]
  10.        
  11.        
  12. class Book(BaseMedia):
  13.     author = models.CharField(max_length=100, validators=[MinLengthValidator(5, message="Author must be at least 5 characters long")])
  14.     isbn = models.CharField(max_length=20, unique=True, validators=[MinLengthValidator(6, message="ISBN must be at least 6 characters long")])
  15.    
  16.     class Meta(BaseMedia.Meta):
  17.         verbose_name = "Model Book"
  18.         verbose_name_plural = "Models of type - Book"
  19.    
  20. class Movie(BaseMedia):
  21.     director = models.CharField(max_length=100, validators=[MinLengthValidator(8, message="Director must be at least 8 characters long")])
  22.    
  23.     class Meta(BaseMedia.Meta):
  24.         verbose_name = "Model Movie"
  25.         verbose_name_plural = "Models of type - Movie"
  26.    
  27.    
  28. class Music(BaseMedia):
  29.     artist = models.CharField(max_length=100, validators=[MinLengthValidator(9, message="Artist must be at least 9 characters long")])
  30.    
  31.     class Meta(BaseMedia.Meta):
  32.         verbose_name = "Model Music"
  33.         verbose_name_plural = "Models of type - Music "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement