remove must_of_the_week field
This commit is contained in:
parent
6924452569
commit
bfd8044b47
|
|
@ -210,25 +210,6 @@ class CarouselQuerySet(models.QuerySet):
|
|||
"""Filter collection by country code."""
|
||||
return self.filter(country__code=code)
|
||||
|
||||
def create_or_destroy(self, instance_to_bind, country):
|
||||
"""Creates or destroys Carousel instance depending on instance fields"""
|
||||
toggle = True
|
||||
kwargs = {
|
||||
'content_type': ContentType.objects.get_for_model(instance_to_bind),
|
||||
'object_id': instance_to_bind.pk,
|
||||
'country': country,
|
||||
}
|
||||
if toggle is None:
|
||||
return
|
||||
elif toggle:
|
||||
kwargs.update({
|
||||
'is_parse': True,
|
||||
'active': True,
|
||||
})
|
||||
self.create(**kwargs)
|
||||
else:
|
||||
self.filter(**kwargs).delete()
|
||||
|
||||
|
||||
class Carousel(models.Model):
|
||||
"""Carousel model."""
|
||||
|
|
|
|||
17
apps/news/migrations/0048_remove_news_must_of_the_week.py
Normal file
17
apps/news/migrations/0048_remove_news_must_of_the_week.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-19 13:47
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('news', '0047_remove_news_start'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='news',
|
||||
name='must_of_the_week',
|
||||
),
|
||||
]
|
||||
|
|
@ -230,7 +230,6 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
|||
verbose_name=_('Duplication datetime'))
|
||||
duplication_uuid = models.UUIDField(default=uuid.uuid4, editable=True, unique=False,
|
||||
verbose_name=_('Field to detect doubles'))
|
||||
must_of_the_week = models.BooleanField(default=False, verbose_name=_('Show in the carousel'))
|
||||
objects = NewsQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
|
|
@ -251,6 +250,11 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi
|
|||
self.duplication_date = timezone.now()
|
||||
self.save()
|
||||
|
||||
@property
|
||||
def must_of_the_week(self) -> bool:
|
||||
"""Detects whether current item in carousel"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def publication_datetime(self):
|
||||
"""Represents datetime object combined from `publication_date` & `publication_time` fields"""
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
extra_kwargs = {
|
||||
'duplication_date': {'read_only': True},
|
||||
'locale_to_description_is_active': {'allow_null': False},
|
||||
'must_of_the_week': {'allow_null': False},
|
||||
'must_of_the_week': {'read_only': True},
|
||||
}
|
||||
|
||||
def create(self, validated_data):
|
||||
|
|
@ -203,9 +203,7 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
slugs__values__contains=list(slugs.values())
|
||||
).exists():
|
||||
raise serializers.ValidationError({'slugs': _('News with this slug already exists.')})
|
||||
instance = super().create(validated_data)
|
||||
Carousel.objects.create_or_destroy(instance, instance.country)
|
||||
return instance
|
||||
return super().create(validated_data)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
slugs = validated_data.get('slugs')
|
||||
|
|
@ -214,10 +212,7 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
slugs__values__contains=list(slugs.values())
|
||||
).exclude(pk=instance.pk).exists():
|
||||
raise serializers.ValidationError({'slugs': _('News with this slug already exists.')})
|
||||
ret = super().update(instance, validated_data)
|
||||
if ret.must_of_the_week != instance.must_of_the_week:
|
||||
Carousel.objects.create_or_destroy(instance, instance.address.city.country)
|
||||
return ret
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
|
||||
class NewsBackOfficeDuplicationInfoSerializer(serializers.ModelSerializer):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user