Add transfer cleaner
Add clean to Country, Region and City
This commit is contained in:
parent
b63809c987
commit
a7513e6ca0
|
|
@ -17,6 +17,8 @@ from news.models import News
|
||||||
from review.models import Review
|
from review.models import Review
|
||||||
from tag.models import TagCategory, ChosenTagSettings
|
from tag.models import TagCategory, ChosenTagSettings
|
||||||
|
|
||||||
|
from transfer.utils import clean_old_records
|
||||||
|
|
||||||
|
|
||||||
def transfer_countries():
|
def transfer_countries():
|
||||||
queryset = transfer_models.Cities.objects.raw("""
|
queryset = transfer_models.Cities.objects.raw("""
|
||||||
|
|
@ -496,6 +498,12 @@ def fix_location_models():
|
||||||
fix_tag_category()
|
fix_tag_category()
|
||||||
fix_chosen_tag()
|
fix_chosen_tag()
|
||||||
|
|
||||||
|
clean_old_records(City, {"mysql_id__isnull": True})
|
||||||
|
clean_old_records(Region, {"mysql_ids__isnull": True})
|
||||||
|
clean_old_records(City, {"mysql_ids__isnull": True})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def transfer_city_gallery():
|
def transfer_city_gallery():
|
||||||
created_counter = 0
|
created_counter = 0
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from importlib.machinery import SourceFileLoader
|
from importlib.machinery import SourceFileLoader
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
def transfer_objects(data_type):
|
def transfer_objects(data_type):
|
||||||
|
|
@ -18,3 +19,19 @@ def transfer_objects(data_type):
|
||||||
for transfer_func in transfer_funcs:
|
for transfer_func in transfer_funcs:
|
||||||
print(f"========================== FUNCTION {transfer_func.__name__} ================================")
|
print(f"========================== FUNCTION {transfer_func.__name__} ================================")
|
||||||
transfer_func()
|
transfer_func()
|
||||||
|
|
||||||
|
|
||||||
|
def clean_old_records(model, conditions):
|
||||||
|
error_file = open(f"{settings.PROJECT_ROOT}/apps/transfer/clear.error.txt", "w")
|
||||||
|
|
||||||
|
try:
|
||||||
|
old_records = model.objects.filter(**conditions)
|
||||||
|
except Exception as e:
|
||||||
|
error_file.write(f"Cannot find model objects: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
for old_record in old_records:
|
||||||
|
try:
|
||||||
|
old_record.delete()
|
||||||
|
except Exception as e:
|
||||||
|
error_file.write(f"Cannot delete object {old_record}: {e}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user