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 pprint import pprint
|
||||
|
||||
|
|
@ -12,10 +12,24 @@ def transfer_countries():
|
|||
else:
|
||||
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 = {
|
||||
"dictionaries": [
|
||||
transfer_countries,
|
||||
|
||||
],
|
||||
"tmp": [
|
||||
transfer_regions
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ class Command(BaseCommand):
|
|||
'subscriber',
|
||||
'recipe',
|
||||
'partner',
|
||||
'gallery'
|
||||
'gallery',
|
||||
|
||||
'tmp'
|
||||
]
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from rest_framework import serializers
|
||||
from location.models import Country
|
||||
from location.models import Country, Region
|
||||
|
||||
|
||||
class CountrySerializer(serializers.ModelSerializer):
|
||||
|
|
@ -22,5 +22,26 @@ class CountrySerializer(serializers.ModelSerializer):
|
|||
return Country
|
||||
|
||||
def get_country_code(self, obj):
|
||||
print(f"OBJECT: {obj}")
|
||||
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