Tmp commit
This commit is contained in:
parent
106ddb044e
commit
c61d5321a9
|
|
@ -1,4 +1,4 @@
|
||||||
from transfer.serializers.location import CountrySerializer
|
from transfer.serializers.location import CountrySerializer, RegionSerializer
|
||||||
from transfer.models import Cities
|
from transfer.models import Cities
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
@ -12,10 +12,24 @@ def transfer_countries():
|
||||||
else:
|
else:
|
||||||
pprint(f"Country serializer errors: {serialized_data.errors}")
|
pprint(f"Country serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
def transfer_regions():
|
||||||
|
regions_without_subregion_queryset = Cities.objects.\
|
||||||
|
exclude(subregion_code__isnull=False).values('region_code', 'country_code_2', 'subregion_code').distinct()
|
||||||
|
|
||||||
|
serialized_without_subregion = RegionSerializer(data=list(regions_without_subregion_queryset.values()), many=True)
|
||||||
|
if serialized_without_subregion.is_valid():
|
||||||
|
serialized_without_subregion.save()
|
||||||
|
else:
|
||||||
|
pprint(f"Parent regions serializer errors: {serialized_without_subregion.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
"dictionaries": [
|
"dictionaries": [
|
||||||
transfer_countries,
|
transfer_countries,
|
||||||
|
|
||||||
|
],
|
||||||
|
"tmp": [
|
||||||
|
transfer_regions
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ class Command(BaseCommand):
|
||||||
'subscriber',
|
'subscriber',
|
||||||
'recipe',
|
'recipe',
|
||||||
'partner',
|
'partner',
|
||||||
'gallery'
|
'gallery',
|
||||||
|
|
||||||
|
'tmp'
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from location.models import Country
|
from location.models import Country, Region
|
||||||
|
|
||||||
|
|
||||||
class CountrySerializer(serializers.ModelSerializer):
|
class CountrySerializer(serializers.ModelSerializer):
|
||||||
|
|
@ -22,5 +22,26 @@ class CountrySerializer(serializers.ModelSerializer):
|
||||||
return Country
|
return Country
|
||||||
|
|
||||||
def get_country_code(self, obj):
|
def get_country_code(self, obj):
|
||||||
print(f"OBJECT: {obj}")
|
|
||||||
return obj.get("country_code_2")
|
return obj.get("country_code_2")
|
||||||
|
|
||||||
|
|
||||||
|
class RegionSerializer(serializers.ModelSerializer):
|
||||||
|
region_code = serializers.CharField()
|
||||||
|
subregion_code = serializers.CharField()
|
||||||
|
country_code_2 = serializers.CharField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Region
|
||||||
|
fields = (
|
||||||
|
"region_code",
|
||||||
|
"country_code_2",
|
||||||
|
"subregion_code"
|
||||||
|
)
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
# Some regions may be already in database
|
||||||
|
region, _ = Region.objects.get_or_create(**validated_data)
|
||||||
|
return region
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user