Advertisement
Guest User

Untitled

a guest
Jul 29th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #model Book
  2. class Book(models.Model):
  3.  
  4.  
  5.     #book types and placed
  6.     BIOGRAPHY = 1
  7.     FANTASY = 2
  8.     HISTORICAL = 3
  9.     HORROR = 4
  10.     CLASSIC = 5
  11.     YOUTH_LITHERATURE = 6
  12.     NON_FICTION = 7
  13.     MODERN_LITERATURE = 8
  14.     POETRY = 9
  15.     ADVENTURE = 10
  16.     ESSAYS = 11
  17.     ROMANCE = 12
  18.     SATIRE = 13
  19.     THRILLER = 14
  20.     DRAMA = 15
  21.     NONE = 0
  22.  
  23.     B00K_CHOICES = (
  24.         (BIOGRAPHY,'Biography'),
  25.         (FANTASY, 'Fantasy/Sci-Fi'),
  26.         (HISTORICAL, 'Historical'),
  27.         (HORROR, 'Horror'),
  28.         (CLASSIC, 'Classic'),
  29.         (YOUTH_LITHERATURE, 'Youth Litherature'),
  30.         (NON_FICTION, 'Non-Fiction'),
  31.         (MODERN_LITERATURE, 'Modern Literature'),
  32.         (POETRY, 'Poetry'),
  33.         (ADVENTURE, 'Adventure'),
  34.         (ESSAYS, 'Essays'),
  35.         (ROMANCE, 'Romance'),
  36.         (SATIRE, 'Satire'),
  37.         (THRILLER, 'Thriller'),
  38.         (DRAMA, 'Drama'),
  39.         (NONE, 'No Information'),
  40.     )
  41.  
  42.  
  43.  
  44.  
  45.     book_image = models.ImageField(upload_to='book_image', blank=True, null=True)
  46.     book_name = models.CharField(max_length=255, unique=True)
  47.     book_author = models.ForeignKey(Author, on_delete=models.CASCADE)
  48.     book_types = models.IntegerField(choices=B00K_CHOICES, default= NONE)
  49.     book_description = models.TextField(null=True, blank=True)
  50.     book_pages = models.PositiveIntegerField(null=True, blank=True)
  51.     book_published = models.DateField(null=True, blank=True)
  52.     book_ratings = GenericRelation(Rating, related_query_name='book', default=NONE)
  53.  
  54.  
  55.     def __str__(self):
  56.         return '{}'.format(self.book_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement