# -*- coding: utf-8 -*- from django.core.management.base import BaseCommand, CommandError from city.models import City from country.models import Country cities = [ {'id':'-1563952', 'country':'11', 'url':'canberra-australia', 'ru':u'Канберра', 'en':'Canberra'}, ] """ cities = [ {'id':'-1563952', 'country':'11', 'url':'canberra-australia', 'ru':u'Канберра', 'en':'Canberra'}, {'id':'-1586844', 'country':'11', 'url':'melbourne-australia', 'ru':u'Мельбурн', 'en':'Melbourne'}, {'id':'-1594675', 'country':'11', 'url':'perth-australia', 'ru':u'Перт', 'en':'Perth'}, {'id':'-1555188', 'country':'11', 'url':'adelaide-australia', 'ru':u'Аделаида', 'en':'Adelaide'}, {'id':'-1561728', 'country':'11', 'url':'brisbane-australia', 'ru':u'Брисбен', 'en':'Brisbane'}, {'id':'-1569058', 'country':'11', 'url':'darwin-australia', 'ru':u'Дарвин', 'en':'Darwin'}, {'id':'-1989985', 'country':'10', 'url':'salzburg-austria', 'ru':u'Зальцбург', 'en':'Salzburg'}, {'id':'-1981445', 'country':'10', 'url':'innsbruck-austria', 'ru':u'Инсбрук', 'en':'Innsbruck'}, {'id':'-1982354', 'country':'10', 'url':'klagenfurt-austria', 'ru':u'Клагенфурте', 'en':'Klagenfurt'}, {'id':'-979186', 'country':'8', 'url':'buenos-aires-argentina', 'ru':u'Буэнос-Айрес', 'en':'Buenos Aires'}, {'id':'-1955925', 'country':'17', 'url':'charleroi-belgium', 'ru':u'Шарлеруа', 'en':'Charleroi'}, {'id':'-1953257', 'country':'17', 'url':'antwerp-belgium', 'ru':u'Антверпен', 'en':'Antwerp'}, {'id':'-1955538', 'country':'17', 'url':'brussels-belgium', 'ru':u'Брюссель', 'en':'Brussels'}, {'id':'-1958757', 'country':'17', 'url':'ghent-belgium', 'ru':u'Гент', 'en':'Ghent'}, {'id':'-1963947', 'country':'17', 'url':'leuven-belgium', 'ru':u'Левен', 'en':'Leuven'}, {'id':'-1964016', 'country':'17', 'url':'liege-belgium', 'ru':u'Льеж', 'en':'Liège'}, {'id':'-1965564', 'country':'17', 'url':'mons-belgium', 'ru':u'Монс', 'en':'Mons'}, {'id':'-1956109', 'country':'17', 'url':'ciney-belgium', 'ru':u'Сине', 'en':'Ciney'}, {'id':'-1959925', 'country':'17', 'url':'hasselt-belgium', 'ru':u'Хасселт', 'en':'Hasselt'}, {'id':'-629138', 'country':'27', 'url':'belo-horizonte-brazil', 'ru':u'Белу-Оризонти', 'en':'Belo Horizonte'}, {'id':'-663509', 'country':'27', 'url':'porto-alegre-brazil', 'ru':u'Порту-Алегри', 'en':'Porto Alegre'}, {'id':'-629039', 'country':'27', 'url':'Belem-brazil', 'ru':u'Белем', 'en':'Belém'}, {'id':'-644901', 'country':'27', 'url':'goiania-brazil', 'ru':u'Гояния', 'en':'Goiânia'}, {'id':'-653186', 'country':'27', 'url':'manaus-brazil', 'ru':u'Манаус', 'en':'Manaus'}, {'id':'-657942', 'country':'27', 'url':'olinda-brazil', 'ru':u'Olinda', 'en':'Olinda'}, {'id':'-657510', 'country':'27', 'url':'novo-hamburgo-brazil', 'ru':u'Novo Hamburgo', 'en':'Novo Hamburgo'}, {'id':'-2112243', 'country':'84', 'url':'surat-india', 'ru':u'Сурат', 'en':'Sūrat'}, {'id':'-3102179', 'country':'85', 'url':'basrah-iraq', 'ru':u'Басра', 'en':'Basrah'}, {'id':'-559845', 'country':'33', 'url':'abbotsford-canada', 'ru':u'Abbotsford', 'en':'Abbotsford'}, {'id':'-561990', 'country':'33', 'url':'calgary-canada', 'ru':u'Калгари', 'en':'Calgary'}, {'id':'-571851', 'country':'33', 'url':'quebec-canada', 'ru':u'Квебек', 'en':'Quebec'}, {'id':'-569541', 'country':'33', 'url':'montreal-canada', 'ru':u'Монреаль', 'en':'Montreal'}, {'id':'-570760', 'country':'33', 'url':'ottawa-canada', 'ru':u'Оттава', 'en':'Ottawa'}, {'id':'-567785', 'country':'33', 'url':'laval-canada', 'ru':u'Лаваль', 'en':'Laval'}, {'id':'-564968', 'country':'33', 'url':'fredericton-canada', 'ru':u'Фредериктон', 'en':'Fredericton'}, {'id':'-564064', 'country':'33', 'url':'edmonton-canada', 'ru':u'Эдмонтон', 'en':'Edmonton'}, {'id':'-569498', 'country':'33', 'url':'moncton-canada', 'ru':u'Монктон', 'en':'Moncton'}, {'id':'-562447', 'country':'33', 'url':'charlottetown-canada', 'ru':u'Шарлоттаун', 'en':'Charlottetown'}, {'id':'-2764584', 'country':'147', 'url':'karachi-pakistan', 'ru':u'Карачи', 'en':'Karachi'}, {'id':'-2767043', 'country':'147', 'url':'lahore-pakistan', 'ru':u'Лахор', 'en':'Lahore'}, ] """ class Command(BaseCommand): def handle(self, *args, **options): for city in cities: #City.objects.get(id=city['id']).delete() country = Country.objects.get(id=city['country']) c = City(id=city['id'], country=country, url=city['url']) c.translate('ru') c.name = city['ru'] print('pre save %s'%str(c)) c.save() print('post save %s'%str(c))