refactoring
This commit is contained in:
parent
439fb17778
commit
51da45b00b
|
|
@ -224,12 +224,12 @@ class EstablishmentQuerySet(models.QuerySet):
|
|||
.filter(**filters) \
|
||||
.annotate_distance(point=establishment.location)
|
||||
|
||||
def similar_restaurants(self, restaurant_slug):
|
||||
def similar_restaurants(self, slug):
|
||||
"""
|
||||
Return QuerySet with objects that similar to Restaurant.
|
||||
:param restaurant_slug: str Establishment slug
|
||||
"""
|
||||
restaurant_qs = self.filter(slug=restaurant_slug,
|
||||
restaurant_qs = self.filter(slug=slug,
|
||||
public_mark__isnull=False)
|
||||
if restaurant_qs.exists():
|
||||
establishment = restaurant_qs.first()
|
||||
|
|
@ -260,12 +260,12 @@ class EstablishmentQuerySet(models.QuerySet):
|
|||
"""
|
||||
return self.filter(wine_origin__wine_sub_region=wine_sub_region).distinct()
|
||||
|
||||
def similar_wineries(self, winery_slug: str):
|
||||
def similar_wineries(self, slug: str):
|
||||
"""
|
||||
Return QuerySet with objects that similar to Winery.
|
||||
:param establishment_slug: str Establishment slug
|
||||
"""
|
||||
winery_qs = self.filter(slug=winery_slug)
|
||||
winery_qs = self.filter(slug=slug)
|
||||
if winery_qs.exists():
|
||||
winery = winery_qs.first()
|
||||
return self.similar_base(winery) \
|
||||
|
|
@ -276,7 +276,7 @@ class EstablishmentQuerySet(models.QuerySet):
|
|||
.distinct('distance', 'wine_origins__wine_region',
|
||||
'wine_origins__wine_sub_region', 'id')
|
||||
else:
|
||||
self.none()
|
||||
return self.none()
|
||||
|
||||
def last_reviewed(self, point: Point):
|
||||
"""
|
||||
|
|
@ -498,15 +498,9 @@ class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin,
|
|||
def visible_tags(self):
|
||||
return super().visible_tags \
|
||||
.exclude(category__index_name__in=['guide', 'collection', 'purchased_item',
|
||||
'business_tag', 'business_tags_de']) \
|
||||
.exclude(value__in=['rss', 'rss_selection'])
|
||||
'business_tag', 'business_tags_de', 'tag'])
|
||||
# todo: recalculate toque_number
|
||||
|
||||
@property
|
||||
def visible_tags_detail(self):
|
||||
"""Removes some tags from detail Establishment representation"""
|
||||
return self.visible_tags.exclude(category__index_name__in=['tag'])
|
||||
|
||||
def recalculate_toque_number(self):
|
||||
toque_number = 0
|
||||
if self.address and self.public_mark:
|
||||
|
|
@ -871,6 +865,25 @@ class ContactEmail(models.Model):
|
|||
return f'{self.email}'
|
||||
|
||||
|
||||
#
|
||||
# class Wine(TranslatedFieldsMixin, models.Model):
|
||||
# """Wine model."""
|
||||
# establishment = models.ForeignKey(
|
||||
# 'establishment.Establishment', verbose_name=_('establishment'),
|
||||
# on_delete=models.CASCADE)
|
||||
# bottles = models.IntegerField(_('bottles'))
|
||||
# price_min = models.DecimalField(
|
||||
# _('price min'), max_digits=14, decimal_places=2)
|
||||
# price_max = models.DecimalField(
|
||||
# _('price max'), max_digits=14, decimal_places=2)
|
||||
# by_glass = models.BooleanField(_('by glass'))
|
||||
# price_glass_min = models.DecimalField(
|
||||
# _('price min'), max_digits=14, decimal_places=2)
|
||||
# price_glass_max = models.DecimalField(
|
||||
# _('price max'), max_digits=14, decimal_places=2)
|
||||
#
|
||||
|
||||
|
||||
class Plate(TranslatedFieldsMixin, models.Model):
|
||||
"""Plate model."""
|
||||
STR_FIELD_NAME = 'name'
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ urlpatterns = [
|
|||
name='create-destroy-favorites'),
|
||||
|
||||
# similar establishments
|
||||
path('slug/<slug:slug>/similar/restaurants/', views.RestaurantSimilarListView.as_view(),
|
||||
path('slug/<slug:slug>/similar/', views.RestaurantSimilarListView.as_view(),
|
||||
name='similar-restaurants'),
|
||||
path('slug/<slug:slug>/similar/wineries/', views.WinerySimilarListView.as_view(),
|
||||
name='similar-restaurants'),
|
||||
|
|
|
|||
|
|
@ -88,8 +88,8 @@ class RestaurantSimilarListView(EstablishmentSimilarList):
|
|||
|
||||
def get_queryset(self):
|
||||
"""Override get_queryset method"""
|
||||
qs = super().get_queryset()
|
||||
return qs.similar_restaurants(restaurant_slug=self.kwargs.get('slug'))
|
||||
return EstablishmentMixinView.get_queryset(self) \
|
||||
.similar_restaurants(slug=self.kwargs.get('slug'))
|
||||
|
||||
|
||||
class WinerySimilarListView(EstablishmentSimilarList):
|
||||
|
|
@ -97,8 +97,8 @@ class WinerySimilarListView(EstablishmentSimilarList):
|
|||
|
||||
def get_queryset(self):
|
||||
"""Override get_queryset method"""
|
||||
qs = super().get_queryset()
|
||||
return qs.similar_wineries(winery_slug=self.kwargs.get('slug'))
|
||||
return EstablishmentMixinView.get_queryset(self) \
|
||||
.similar_wineries(slug=self.kwargs.get('slug'))
|
||||
|
||||
|
||||
class EstablishmentTypeListView(generics.ListAPIView):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user