parent
ca5000b695
commit
fc471e131f
3 changed files with 4 additions and 42 deletions
@ -1,36 +0,0 @@ |
||||
# -*- 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) |
||||
Loading…
Reference in new issue