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.
36 lines
1.3 KiB
36 lines
1.3 KiB
# -*- coding: utf-8 -*-
|
|
import MySQLdb
|
|
from MySQLdb.cursors import DictCursor
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from directories.models import Currency
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
# local database(will not work on production)
|
|
db = MySQLdb.connect(host="localhost",
|
|
user="root",
|
|
passwd="qazedc",
|
|
db="test",
|
|
charset='utf8',
|
|
cursorclass=DictCursor)
|
|
cursor = db.cursor()
|
|
# !!!database can change
|
|
sql = "SELECT code, name FROM localization.currencies;"
|
|
cursor.execute(sql)
|
|
result = cursor.fetchall()
|
|
for item in result:
|
|
try:
|
|
currency = Currency.objects.get(code=item['code'])
|
|
print('currency with code %s already exist'%currency.code)
|
|
continue
|
|
except Currency.DoesNotExist:
|
|
currency = Currency(code=item['code'])
|
|
|
|
currency.translate('ru')
|
|
currency.name = item['name']
|
|
currency.save()
|
|
currency.translate('en')
|
|
currency.name = item['name']
|
|
currency.save()
|
|
print(currency.code) |