Advertisement
horozov86

6. Mixin

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