From 0889ad30442bd0ca30607d5ad4f9ba7839e57ab4 Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Wed, 11 Jun 2014 10:57:45 +0530 Subject: [PATCH] cities importer --- itf/itfprofiles/importer.py | 21 +++++++++++++++++++++ itf/itfprofiles/models.py | 21 ++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 itf/itfprofiles/importer.py diff --git a/itf/itfprofiles/importer.py b/itf/itfprofiles/importer.py new file mode 100644 index 0000000..a998f10 --- /dev/null +++ b/itf/itfprofiles/importer.py @@ -0,0 +1,21 @@ +from itfprofiles.models import City, STATE_CHOICES +import csv + +def import_cities(csv_filename): + csv_file = open(csv_filename) + csv_reader = csv.reader(csv_file) + for row in csv_reader: + city = row[0] + state = row[1] + state_no = get_state(state) + c = City(name=city, state=state_no) + c.save() + print city + + +def get_state(name): + no = None + for s in STATE_CHOICES: + if name == s[1]: + return s[0] + print "State %s not found" % name diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index fb4f0a3..5a9436e 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -229,10 +229,10 @@ class Note(ItfModel): STATE_CHOICES= ( - ('0', 'Andaman and Nicobar'), + ('0', 'Andaman and Nicobar Islands'), ('1', 'Andhra Pradesh'), ('2', 'Arunachal Pradesh'), - ('3', 'Asom (Assam)'), + ('3', 'Assam'), ('4', 'Bihar'), ('5', 'Chandigarh'), ('6', 'Chhattisgarh'), @@ -243,7 +243,7 @@ STATE_CHOICES= ( ('11', 'Gujarat'), ('12', 'Haryana'), ('13', 'Himachal Pradesh'), - ('14', 'Jammu And Kashmir'), + ('14', 'Jammu and Kashmir'), ('15', 'Jharkhand'), ('16', 'Karnataka'), ('17', 'Kerala'), @@ -254,17 +254,19 @@ STATE_CHOICES= ( ('22', 'Meghalaya'), ('23', 'Mizoram'), ('24', 'Nagaland'), - ('25', 'Odisha(Orrisa)'), + ('25', 'Odisha'), ('26', 'Pondicherry'), ('27', 'Punjab'), ('28', 'Rajasthan'), ('29', 'Sikkim'), - ('30', 'Tamilnadu'), + ('30', 'Tamil Nadu'), ('31', 'Tripura'), - ('32', 'Uttarakhand (Uttaranchal)'), + ('32', 'Uttarakhand'), ('33', 'Uttar Pradesh'), ('34', 'West Bengal'), - ('35', 'Not Applicable'), + ('35', 'Telangana'), + ('36', 'Puducherry'), + ('100', 'Not Applicable'), ) class City(models.Model): @@ -570,10 +572,11 @@ class GroupOccupation(models.Model): def __unicode__(self): return self.name + class GroupGroupOccupation(models.Model): theatregroup = models.ForeignKey("TheatreGroup") - groupoccupation = models.ForeignKey("GroupOccupation", verbose_name="Occupation") - is_main = models.BooleanField(default=False, verbose_name="Is this the group's main occupation?") + groupoccupation = models.ForeignKey("GroupOccupation", verbose_name="Nature of work") + is_main = models.BooleanField(default=False, verbose_name="Is this the group's main field of work?")