Directories refactor

remotes/origin/1203
Nazar Kotjuk 10 years ago
parent ca5000b695
commit fc471e131f
  1. 1
      country/models.py
  2. 36
      directories/management/commands/fill_currencies.py
  3. 9
      directories/models.py

@ -12,7 +12,6 @@ from directories.models import Language, Currency
from city.models import City from city.models import City
from exposition.models import Exposition from exposition.models import Exposition
from place_exposition.models import PlaceExposition from place_exposition.models import PlaceExposition
from organiser.models import Organiser
from conference.models import Conference from conference.models import Conference
from seminar.models import Seminar from seminar.models import Seminar
from webinar.models import Webinar from webinar.models import Webinar

@ -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)

@ -5,7 +5,7 @@ from hvad.models import TranslatableModel, TranslatedFields, TranslationManager
class Language(TranslatableModel): class Language(TranslatableModel):
""" """
Creates Language model stores information about languages used in Country model
""" """
language = models.CharField(max_length=255)# native language name language = models.CharField(max_length=255)# native language name
code = models.CharField(max_length=2) code = models.CharField(max_length=2)
@ -19,7 +19,7 @@ class Language(TranslatableModel):
class Currency(TranslatableModel): class Currency(TranslatableModel):
""" """
Creates Currency model stores information about curencies used in Country model
""" """
code = models.CharField(max_length=3) code = models.CharField(max_length=3)
@ -32,11 +32,10 @@ class Currency(TranslatableModel):
class Iata (models.Model): class Iata (models.Model):
""" """
Creates Iata model stores information about iata codes used in City model
""" """
airport = models.CharField(max_length=255) airport = models.CharField(max_length=255)
code = models.CharField(max_length=4) code = models.CharField(max_length=4)
def __unicode__(self): def __unicode__(self):
return self.code return self.code
Loading…
Cancel
Save