From fc471e131fcb9cd78d267af8275fe1a6021206b5 Mon Sep 17 00:00:00 2001 From: Nazar Kotjuk Date: Mon, 26 Oct 2015 16:55:07 +0200 Subject: [PATCH] Directories refactor --- country/models.py | 1 - .../management/commands/fill_currencies.py | 36 ------------------- directories/models.py | 9 +++-- 3 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 directories/management/commands/fill_currencies.py diff --git a/country/models.py b/country/models.py index 4e7c27d9..d4125c12 100644 --- a/country/models.py +++ b/country/models.py @@ -12,7 +12,6 @@ from directories.models import Language, Currency from city.models import City from exposition.models import Exposition from place_exposition.models import PlaceExposition -from organiser.models import Organiser from conference.models import Conference from seminar.models import Seminar from webinar.models import Webinar diff --git a/directories/management/commands/fill_currencies.py b/directories/management/commands/fill_currencies.py deleted file mode 100644 index 6122cee9..00000000 --- a/directories/management/commands/fill_currencies.py +++ /dev/null @@ -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) \ No newline at end of file diff --git a/directories/models.py b/directories/models.py index 74b0d266..87d0a73d 100644 --- a/directories/models.py +++ b/directories/models.py @@ -5,7 +5,7 @@ from hvad.models import TranslatableModel, TranslatedFields, TranslationManager class Language(TranslatableModel): """ - Creates Language model + stores information about languages used in Country model """ language = models.CharField(max_length=255)# native language name code = models.CharField(max_length=2) @@ -19,7 +19,7 @@ class Language(TranslatableModel): class Currency(TranslatableModel): """ - Creates Currency model + stores information about curencies used in Country model """ code = models.CharField(max_length=3) @@ -32,11 +32,10 @@ class Currency(TranslatableModel): class Iata (models.Model): """ - Creates Iata model + stores information about iata codes used in City model """ airport = models.CharField(max_length=255) code = models.CharField(max_length=4) def __unicode__(self): - return self.code - + return self.code \ No newline at end of file