You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
1.2 KiB

# -*- coding: utf-8 -*-
import MySQLdb
from MySQLdb.cursors import DictCursor
from django.core.management.base import BaseCommand, CommandError
from django.utils import translation
from country.models import Country
def get_from_old(country):
db = MySQLdb.connect(host="localhost",
user="kotzilla",
passwd="qazedc",
db="test2",
charset='utf8',
cursorclass=DictCursor)
cursor = db.cursor()
sql = """SELECT url, inflect FROM old_expomap.products_places WHERE title="%(name)s" """%{'name': country.name.encode('utf-8')}
#print(country.name.encode('utf-8'))
# print(sql)
cursor.execute(sql)
result = cursor.fetchone()
return result
class Command(BaseCommand):
def handle(self, *args, **options):
translation.activate('ru')
for country in Country.objects.all():
old_data = get_from_old(country)
if old_data is None:
continue
country.old_url = old_data['url']
country.inflect = old_data['inflect']
try:
country.save()
print(country)
except:
continue