Add correction location.country for collections
This commit is contained in:
parent
70ec095b12
commit
96fd106cca
|
|
@ -1,12 +1,12 @@
|
|||
from transfer.serializers import location as location_serializers
|
||||
from transfer import models as transfer_models
|
||||
from location.models import Country, Region, City, Address
|
||||
from location.models import Country, Region, City, Address, WineRegion
|
||||
from pprint import pprint
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import MultipleObjectsReturned
|
||||
|
||||
from collection.models import Collection
|
||||
from requests import get
|
||||
|
||||
|
||||
|
|
@ -369,17 +369,40 @@ def fix_location_address():
|
|||
address.save()
|
||||
|
||||
|
||||
def fix_location_collection():
|
||||
collections = Collection.objects.filter(old_id__isnull=False)
|
||||
for collection in collections:
|
||||
try:
|
||||
mysql_collection = transfer_models.Collections.objects.\
|
||||
raw(f"""select
|
||||
s.country_code_2,
|
||||
c.id
|
||||
from collections as c
|
||||
join sites s on s.id = c.site_id where c.id={collection.old_id}""")[0]
|
||||
except:
|
||||
continue
|
||||
|
||||
try:
|
||||
correct_country = Country.objects.get(code=mysql_collection.country_code_2, mysql_ids__isnull=False)
|
||||
except Country.DoesNotExist:
|
||||
continue
|
||||
|
||||
collection.country = correct_country
|
||||
collection.save()
|
||||
|
||||
|
||||
def fix_location_models():
|
||||
|
||||
try:
|
||||
ruby_data_file = open(f"{settings.PROJECT_ROOT}/apps/location/ruby_data.py", "r")
|
||||
ruby_data = json.loads(ruby_data_file.read())
|
||||
except FileNotFoundError:
|
||||
ruby_data = get_ruby_data()
|
||||
|
||||
add_correct_location_models(ruby_data)
|
||||
|
||||
fix_location_address()
|
||||
# try:
|
||||
# ruby_data_file = open(f"{settings.PROJECT_ROOT}/apps/location/ruby_data.py", "r")
|
||||
# ruby_data = json.loads(ruby_data_file.read())
|
||||
# except FileNotFoundError:
|
||||
# ruby_data = get_ruby_data()
|
||||
#
|
||||
# add_correct_location_models(ruby_data)
|
||||
#
|
||||
# fix_location_address()
|
||||
fix_location_collection()
|
||||
|
||||
|
||||
data_types = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user