Tmp
This commit is contained in:
parent
bf375f3370
commit
abe8eae655
|
|
@ -12,9 +12,13 @@ def transfer_countries():
|
||||||
else:
|
else:
|
||||||
pprint(f"Country serializer errors: {serialized_data.errors}")
|
pprint(f"Country serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
def transfer_regions():
|
def transfer_regions():
|
||||||
regions_without_subregion_queryset = Cities.objects.\
|
regions_without_subregion_queryset = Cities.objects.\
|
||||||
exclude(subregion_code__isnull=False).values('region_code', 'country_code_2', 'subregion_code').distinct()
|
exclude(subregion_code__isnull=True).\
|
||||||
|
exclude(region_code__isnull=True).\
|
||||||
|
exclude(country_code_2__isnull=True).\
|
||||||
|
values('region_code', 'country_code_2', 'subregion_code').distinct()
|
||||||
|
|
||||||
serialized_without_subregion = RegionSerializer(data=list(regions_without_subregion_queryset.values()), many=True)
|
serialized_without_subregion = RegionSerializer(data=list(regions_without_subregion_queryset.values()), many=True)
|
||||||
if serialized_without_subregion.is_valid():
|
if serialized_without_subregion.is_valid():
|
||||||
|
|
@ -23,7 +27,6 @@ def transfer_regions():
|
||||||
pprint(f"Parent regions serializer errors: {serialized_without_subregion.errors}")
|
pprint(f"Parent regions serializer errors: {serialized_without_subregion.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
"dictionaries": [
|
"dictionaries": [
|
||||||
transfer_countries,
|
transfer_countries,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class CountrySerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class RegionSerializer(serializers.ModelSerializer):
|
class RegionSerializer(serializers.ModelSerializer):
|
||||||
region_code = serializers.CharField()
|
region_code = serializers.CharField()
|
||||||
subregion_code = serializers.CharField()
|
subregion_code = serializers.CharField(allow_null=True)
|
||||||
country_code_2 = serializers.CharField()
|
country_code_2 = serializers.CharField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -39,6 +39,17 @@ class RegionSerializer(serializers.ModelSerializer):
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
|
data['code'] = data.pop('region_code')
|
||||||
|
if "country_code_2" in data and data["country_code_2"] is not None:
|
||||||
|
try:
|
||||||
|
country = Country.objects.get(code=data['country_code_2'])
|
||||||
|
data.country = country
|
||||||
|
del (data['country_code_2'])
|
||||||
|
|
||||||
|
except Country.DoesNotExist as e:
|
||||||
|
print(f"Country error: {e}")
|
||||||
|
|
||||||
|
del(data['subregion_code'])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user