must_of_the_week behaviour for update. public_mark has been returned
This commit is contained in:
parent
3da4dfd54b
commit
c6e12f3320
|
|
@ -232,6 +232,8 @@ class EstablishmentRUDSerializer(model_serializers.EstablishmentBaseSerializer):
|
||||||
|
|
||||||
last_review = ReviewBaseSerializer(read_only=True)
|
last_review = ReviewBaseSerializer(read_only=True)
|
||||||
|
|
||||||
|
must_of_the_week = serializers.BooleanField(required=False, )
|
||||||
|
|
||||||
class Meta(model_serializers.EstablishmentBaseSerializer.Meta):
|
class Meta(model_serializers.EstablishmentBaseSerializer.Meta):
|
||||||
fields = [
|
fields = [
|
||||||
'id',
|
'id',
|
||||||
|
|
@ -264,6 +266,7 @@ class EstablishmentRUDSerializer(model_serializers.EstablishmentBaseSerializer):
|
||||||
'must_of_the_week',
|
'must_of_the_week',
|
||||||
'last_update_by_gm',
|
'last_update_by_gm',
|
||||||
'last_update_by_manager',
|
'last_update_by_manager',
|
||||||
|
'public_mark',
|
||||||
]
|
]
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
|
|
|
||||||
|
|
@ -542,22 +542,42 @@ class AwardsModelMixin:
|
||||||
|
|
||||||
|
|
||||||
class CarouselMixin:
|
class CarouselMixin:
|
||||||
|
def __must_of_the_week_info_from_self(self) -> dict:
|
||||||
|
from main.models import Country
|
||||||
|
|
||||||
|
return {
|
||||||
|
'content_type': ContentType.objects.get_for_model(self),
|
||||||
|
'object_id': getattr(self, 'pk'),
|
||||||
|
'country': getattr(self, 'country', get_object_or_404(Country, id=getattr(self, 'country_id', 0))),
|
||||||
|
}
|
||||||
|
|
||||||
|
def __must_of_the_week_has_fields(self) -> bool:
|
||||||
|
return hasattr(self, 'pk') and (hasattr(self, 'country') or hasattr(self, 'country_id'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def must_of_the_week(self) -> bool:
|
def must_of_the_week(self) -> bool:
|
||||||
|
from main import models as main_models
|
||||||
|
|
||||||
"""Detects whether current item in carousel"""
|
"""Detects whether current item in carousel"""
|
||||||
from main.models import Carousel
|
if self.__must_of_the_week_has_fields():
|
||||||
|
kwargs = self.__must_of_the_week_info_from_self()
|
||||||
if hasattr(self, 'pk') and (hasattr(self, 'country') or hasattr(self, 'country_id')):
|
return main_models.Carousel.objects.filter(**kwargs).exists()
|
||||||
kwargs = {
|
|
||||||
'content_type': ContentType.objects.get_for_model(self),
|
|
||||||
'object_id': self.pk,
|
|
||||||
'country': getattr(self, 'country', getattr(self, 'country_id', None)),
|
|
||||||
}
|
|
||||||
|
|
||||||
return Carousel.objects.filter(**kwargs).exists()
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@must_of_the_week.setter
|
||||||
|
def must_of_the_week(self, status: bool):
|
||||||
|
from main import models as main_models
|
||||||
|
|
||||||
|
"""Update field by status"""
|
||||||
|
if status != self.must_of_the_week and self.__must_of_the_week_has_fields():
|
||||||
|
carousel, _ = main_models.Carousel.objects.get_or_create(
|
||||||
|
**self.__must_of_the_week_info_from_self()
|
||||||
|
)
|
||||||
|
|
||||||
|
if not status and isinstance(carousel, main_models.Carousel):
|
||||||
|
carousel.delete()
|
||||||
|
|
||||||
|
|
||||||
class UpdateByMixin(models.Model):
|
class UpdateByMixin(models.Model):
|
||||||
"""Modify by mixin"""
|
"""Modify by mixin"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user