Advertisement
horozov86

5. Menu Review

Nov 22nd, 2023
688
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. class RestaurantReview(models.Model):
  2.     reviewer_name = models.CharField(max_length=100)
  3.     restaurant = models.ForeignKey("Restaurant", on_delete=models.CASCADE)
  4.     review_content = models.TextField()
  5.     rating = models.PositiveIntegerField(validators=[validators.MaxValueValidator(5)])
  6.    
  7.     class Meta:
  8.         abstract = True
  9.         ordering = ["-rating"]
  10.         verbose_name = "Restaurant Review"
  11.         verbose_name_plural = "Restaurant Reviews"
  12.         unique_together = ["reviewer_name", "restaurant"]
  13.        
  14.        
  15. class RegularRestaurantReview(RestaurantReview):
  16.     pass
  17.  
  18.  
  19. class FoodCriticRestaurantReview(RestaurantReview):
  20.     food_critic_cuisine_area = models.CharField(max_length=100)
  21.    
  22.     class Meta:
  23.         ordering = ["-rating"]
  24.         verbose_name = "Food Critic Review"
  25.         verbose_name_plural = "Food Critic Reviews"
  26.         unique_together = ["reviewer_name", "restaurant"]
  27.        
  28.        
  29. class MenuReview(models.Model):
  30.     reviewer_name = models.CharField(max_length=100)
  31.     menu = models.ForeignKey("Menu", on_delete=models.CASCADE)
  32.     review_content = models.TextField()
  33.     rating = models.PositiveIntegerField(validators=[validators.MaxValueValidator(5)])
  34.    
  35.     class Meta:
  36.         ordering = ['-rating']
  37.         verbose_name = "Menu Review"
  38.         verbose_name_plural = "Menu Reviews"
  39.         unique_together = ["reviewer_name", "menu"]
  40.         indexes = [models.Index(field=['menu'], name="main_app_menu_review_menu_id")]
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement