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)
|
||||
|
||||
must_of_the_week = serializers.BooleanField(required=False, )
|
||||
|
||||
class Meta(model_serializers.EstablishmentBaseSerializer.Meta):
|
||||
fields = [
|
||||
'id',
|
||||
|
|
@ -264,6 +266,7 @@ class EstablishmentRUDSerializer(model_serializers.EstablishmentBaseSerializer):
|
|||
'must_of_the_week',
|
||||
'last_update_by_gm',
|
||||
'last_update_by_manager',
|
||||
'public_mark',
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
|
|
|
|||
|
|
@ -542,22 +542,42 @@ class AwardsModelMixin:
|
|||
|
||||
|
||||
class CarouselMixin:
|
||||
@property
|
||||
def must_of_the_week(self) -> bool:
|
||||
"""Detects whether current item in carousel"""
|
||||
from main.models import Carousel
|
||||
def __must_of_the_week_info_from_self(self) -> dict:
|
||||
from main.models import Country
|
||||
|
||||
if hasattr(self, 'pk') and (hasattr(self, 'country') or hasattr(self, 'country_id')):
|
||||
kwargs = {
|
||||
return {
|
||||
'content_type': ContentType.objects.get_for_model(self),
|
||||
'object_id': self.pk,
|
||||
'country': getattr(self, 'country', getattr(self, 'country_id', None)),
|
||||
'object_id': getattr(self, 'pk'),
|
||||
'country': getattr(self, 'country', get_object_or_404(Country, id=getattr(self, 'country_id', 0))),
|
||||
}
|
||||
|
||||
return Carousel.objects.filter(**kwargs).exists()
|
||||
def __must_of_the_week_has_fields(self) -> bool:
|
||||
return hasattr(self, 'pk') and (hasattr(self, 'country') or hasattr(self, 'country_id'))
|
||||
|
||||
@property
|
||||
def must_of_the_week(self) -> bool:
|
||||
from main import models as main_models
|
||||
|
||||
"""Detects whether current item in carousel"""
|
||||
if self.__must_of_the_week_has_fields():
|
||||
kwargs = self.__must_of_the_week_info_from_self()
|
||||
return main_models.Carousel.objects.filter(**kwargs).exists()
|
||||
|
||||
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):
|
||||
"""Modify by mixin"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user