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.
30 lines
1008 B
30 lines
1008 B
# -*- 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 City
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
db = MySQLdb.connect(host="localhost",
|
|
user="kotzilla",
|
|
passwd="qazedc",
|
|
db="test2",
|
|
charset='utf8',
|
|
cursorclass=DictCursor)
|
|
cursor = db.cursor()
|
|
sql = """SELECT title, url, inflect
|
|
FROM old_expomap.products_places
|
|
WHERE parent_id > 0 """
|
|
|
|
|
|
cursor.execute(sql)
|
|
result = cursor.fetchall()
|
|
for res in result:
|
|
name = res['title']
|
|
url = res['url']
|
|
inflect = res['inflect']
|
|
City.objects.filter(translations__name=name).update(inflect=inflect, old_url=url)
|
|
print(name.encode('utf-8')) |