cities importer

This commit is contained in:
Sanjay B 2014-06-11 10:57:45 +05:30
parent ffe4996ff1
commit 0889ad3044
2 changed files with 33 additions and 9 deletions

View File

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

View File

@ -229,10 +229,10 @@ class Note(ItfModel):
STATE_CHOICES= ( STATE_CHOICES= (
('0', 'Andaman and Nicobar'), ('0', 'Andaman and Nicobar Islands'),
('1', 'Andhra Pradesh'), ('1', 'Andhra Pradesh'),
('2', 'Arunachal Pradesh'), ('2', 'Arunachal Pradesh'),
('3', 'Asom (Assam)'), ('3', 'Assam'),
('4', 'Bihar'), ('4', 'Bihar'),
('5', 'Chandigarh'), ('5', 'Chandigarh'),
('6', 'Chhattisgarh'), ('6', 'Chhattisgarh'),
@ -243,7 +243,7 @@ STATE_CHOICES= (
('11', 'Gujarat'), ('11', 'Gujarat'),
('12', 'Haryana'), ('12', 'Haryana'),
('13', 'Himachal Pradesh'), ('13', 'Himachal Pradesh'),
('14', 'Jammu And Kashmir'), ('14', 'Jammu and Kashmir'),
('15', 'Jharkhand'), ('15', 'Jharkhand'),
('16', 'Karnataka'), ('16', 'Karnataka'),
('17', 'Kerala'), ('17', 'Kerala'),
@ -254,17 +254,19 @@ STATE_CHOICES= (
('22', 'Meghalaya'), ('22', 'Meghalaya'),
('23', 'Mizoram'), ('23', 'Mizoram'),
('24', 'Nagaland'), ('24', 'Nagaland'),
('25', 'Odisha(Orrisa)'), ('25', 'Odisha'),
('26', 'Pondicherry'), ('26', 'Pondicherry'),
('27', 'Punjab'), ('27', 'Punjab'),
('28', 'Rajasthan'), ('28', 'Rajasthan'),
('29', 'Sikkim'), ('29', 'Sikkim'),
('30', 'Tamilnadu'), ('30', 'Tamil Nadu'),
('31', 'Tripura'), ('31', 'Tripura'),
('32', 'Uttarakhand (Uttaranchal)'), ('32', 'Uttarakhand'),
('33', 'Uttar Pradesh'), ('33', 'Uttar Pradesh'),
('34', 'West Bengal'), ('34', 'West Bengal'),
('35', 'Not Applicable'), ('35', 'Telangana'),
('36', 'Puducherry'),
('100', 'Not Applicable'),
) )
class City(models.Model): class City(models.Model):
@ -570,10 +572,11 @@ class GroupOccupation(models.Model):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
class GroupGroupOccupation(models.Model): class GroupGroupOccupation(models.Model):
theatregroup = models.ForeignKey("TheatreGroup") theatregroup = models.ForeignKey("TheatreGroup")
groupoccupation = models.ForeignKey("GroupOccupation", verbose_name="Occupation") groupoccupation = models.ForeignKey("GroupOccupation", verbose_name="Nature of work")
is_main = models.BooleanField(default=False, verbose_name="Is this the group's main occupation?") is_main = models.BooleanField(default=False, verbose_name="Is this the group's main field of work?")