Guest User

Untitled

a guest
Dec 10th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.48 KB | None | 0 0
  1. diff --git a/yummy/models.py b/yummy/models.py
  2. index 785b370..a673746 100644
  3. --- a/yummy/models.py
  4. +++ b/yummy/models.py
  5. @@ -283,18 +283,27 @@ class Recipe(models.Model):
  6.          return groups
  7.  
  8.  
  9. -class RecipePhoto(models.Model):
  10. +class PhotoMixin(models.Model):
  11.  
  12. -    objects = managers.RecipePhotoManager()
  13.  
  14. -    recipe = models.ForeignKey(Recipe, verbose_name=_('Recipe'))
  15. +
  16. +    class Meta:
  17. +        abstract = True
  18. +
  19.      photo = models.ForeignKey(Photo, verbose_name=_('Photo'))
  20.      is_visible = models.BooleanField(_('Visible'), default=True)
  21.      order = models.PositiveSmallIntegerField(_('Order'), default=1, db_index=True)
  22.  
  23. +    objects = managers.PhotoManager()
  24. +
  25.      def __unicode__(self):
  26.          return u"%d. %s" % (self.order, self.photo)
  27.  
  28. +
  29. +class RecipePhoto(PhotoMixin):
  30. +
  31. +    recipe = models.ForeignKey(Recipe, verbose_name=_('Recipe'))
  32. +
  33.      class Meta:
  34.          unique_together = (
  35.              ('recipe', 'photo'),
  36. @@ -319,7 +328,8 @@ class RecipePhoto(models.Model):
  37.          - if this value collides, bump following values
  38.              (also make there a gap to fit more photos w/o reordering in there)
  39.          """
  40. -        photos = list(RecipePhoto.objects.filter(recipe=self.recipe).select_related('recipe', 'photo').order_by('order'))
  41. +        photos = list(RecipePhoto.objects.filter(recipe=self.recipe).\
  42. +                        select_related('recipe', 'photo').order_by('order'))
  43.          if not photos:
  44.              return
Add Comment
Please, Sign In to add comment