country for carousel
This commit is contained in:
parent
8787a6b944
commit
7acc8592a8
20
apps/main/migrations/0027_carousel_country.py
Normal file
20
apps/main/migrations/0027_carousel_country.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-11-01 14:23
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('location', '0020_merge_20191030_1714'),
|
||||||
|
('main', '0026_auto_20191101_0500'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='carousel',
|
||||||
|
name='country',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='location.Country', verbose_name='country'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -295,6 +295,13 @@ class Carousel(models.Model):
|
||||||
attachment_suffix_url = models.TextField(_('old attachment_suffix_url'), blank=True, null=True, default=None)
|
attachment_suffix_url = models.TextField(_('old attachment_suffix_url'), blank=True, null=True, default=None)
|
||||||
description = models.CharField(_('old description'), max_length=255, blank=True, null=True, default=None)
|
description = models.CharField(_('old description'), max_length=255, blank=True, null=True, default=None)
|
||||||
link_title = models.CharField(_('old link_title'), max_length=255, blank=True, null=True, default=None)
|
link_title = models.CharField(_('old link_title'), max_length=255, blank=True, null=True, default=None)
|
||||||
|
country = models.ForeignKey(
|
||||||
|
Country,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
verbose_name=_('country')
|
||||||
|
)
|
||||||
active = models.BooleanField(_('old active'), default=False)
|
active = models.BooleanField(_('old active'), default=False)
|
||||||
is_parse = models.BooleanField(_('is parse'), default=False)
|
is_parse = models.BooleanField(_('is parse'), default=False)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
from django.db.models import F
|
||||||
|
|
||||||
from transfer.models import CarouselElements
|
from transfer.models import CarouselElements
|
||||||
from transfer.serializers.carousel import CarouselSerializer
|
from transfer.serializers.carousel import CarouselSerializer
|
||||||
|
|
||||||
|
|
||||||
def transfer_carousel():
|
def transfer_carousel():
|
||||||
queryset = CarouselElements.objects.all()
|
queryset = CarouselElements.objects.all().annotate(
|
||||||
|
country=F('home_page__site__country_code_2'),
|
||||||
|
)
|
||||||
|
|
||||||
serialized_data = CarouselSerializer(data=list(queryset.values()), many=True)
|
serialized_data = CarouselSerializer(data=list(queryset.values()), many=True)
|
||||||
if serialized_data.is_valid():
|
if serialized_data.is_valid():
|
||||||
|
|
|
||||||
|
|
@ -940,12 +940,23 @@ class KeyValueMetadatumKeyValueMetadatumEstablishments(MigrateMixin):
|
||||||
# managed = False
|
# managed = False
|
||||||
# db_table = 'wine_types'
|
# db_table = 'wine_types'
|
||||||
|
|
||||||
|
class HomePages(models.Model):
|
||||||
|
using = 'legacy'
|
||||||
|
|
||||||
|
site = models.ForeignKey(Sites, models.DO_NOTHING, blank=True, null=True)
|
||||||
|
selection_of_week = models.IntegerField(blank=True, null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
managed = False
|
||||||
|
db_table = 'home_pages'
|
||||||
|
|
||||||
|
|
||||||
class CarouselElements(MigrateMixin):
|
class CarouselElements(MigrateMixin):
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
||||||
title = models.CharField(max_length=255, blank=True, null=True)
|
title = models.CharField(max_length=255, blank=True, null=True)
|
||||||
link = models.CharField(max_length=255, blank=True, null=True)
|
link = models.CharField(max_length=255, blank=True, null=True)
|
||||||
home_page_id = models.IntegerField(blank=True, null=True)
|
home_page = models.ForeignKey(HomePages, models.DO_NOTHING, blank=True, null=True)
|
||||||
created_at = models.DateTimeField()
|
created_at = models.DateTimeField()
|
||||||
updated_at = models.DateTimeField()
|
updated_at = models.DateTimeField()
|
||||||
attachment_file_name = models.CharField(max_length=255, blank=True, null=True)
|
attachment_file_name = models.CharField(max_length=255, blank=True, null=True)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from django.contrib.contenttypes.models import ContentType
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from establishment.models import Establishment
|
from establishment.models import Establishment
|
||||||
|
from location.models import Country
|
||||||
from main.models import Carousel
|
from main.models import Carousel
|
||||||
from news.models import News
|
from news.models import News
|
||||||
|
|
||||||
|
|
@ -24,18 +25,26 @@ class CarouselSerializer(serializers.Serializer):
|
||||||
description = serializers.CharField(allow_null=True, allow_blank=True)
|
description = serializers.CharField(allow_null=True, allow_blank=True)
|
||||||
attachment_suffix_url = serializers.CharField(allow_null=True)
|
attachment_suffix_url = serializers.CharField(allow_null=True)
|
||||||
active = serializers.IntegerField()
|
active = serializers.IntegerField()
|
||||||
|
country = serializers.CharField(allow_null=True)
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
object_id, content_type_id = self.get_content_type(validated_data)
|
object_id, content_type_id = self.get_content_type(validated_data)
|
||||||
validated_data.update({
|
validated_data.update({
|
||||||
|
'old_id': validated_data['id'],
|
||||||
|
'country': self.get_country(validated_data),
|
||||||
'active': bool(int(validated_data['active'])),
|
'active': bool(int(validated_data['active'])),
|
||||||
'content_type_id': content_type_id,
|
'content_type_id': content_type_id,
|
||||||
'object_id': object_id,
|
'object_id': object_id,
|
||||||
'is_parse': bool(object_id),
|
'is_parse': bool(object_id),
|
||||||
})
|
})
|
||||||
obj = Carousel.objects.create(**validated_data)
|
validated_data.pop('id')
|
||||||
|
obj, _ = Carousel.objects.update_or_create(**validated_data)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_country(data):
|
||||||
|
return Country.objects.filter(code__iexact=data['country']).first()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_content_type(data):
|
def get_content_type(data):
|
||||||
link = data['link']
|
link = data['link']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user