# Path: elections/models.py
# class Candidate(models.Model):
#     """
#     An election candidate
#     """
#     test_flag = TestFlagField()
#     politician_id = models.IntegerField(primary_key=True)
#     slug = models.SlugField()
#     ap_candidate_id = models.IntegerField(unique=True)
#     candidate_number = models.IntegerField()
#     first_name = models.CharField(blank=True, null=True, max_length=64)
#     middle_name = models.CharField(blank=True, null=True, max_length=64)
#     last_name = models.CharField(blank=True, null=True, max_length=64)
#     junior = models.CharField(blank=True, null=True, max_length=16)
#     use_junior = models.BooleanField(default=False)
#     year_first_elected = models.IntegerField(blank=True, null=True)
#     birth_date = models.DateField(blank=True, null=True)
#     birth_place = models.CharField(blank=True, null=True, max_length=100)
#     birth_state = models.CharField(blank=True, null=True, max_length=2)
#     birth_province = models.CharField(blank=True, null=True, max_length=100)
#     birth_country = models.CharField(blank=True, null=True, max_length=100)
#     residence_place = models.CharField(blank=True, null=True, max_length=100)
#     residence_state = models.CharField(blank=True, null=True, max_length=2)
#     gender = models.CharField(
#         blank=True, null=True, 
#         max_length=1, 
#         choices=(('M', 'Male'), ('F', 'Female')))
#     ethnicity = models.CharField(blank=True, null=True, max_length=100)
#     hispanic = models.CharField(blank=True, null=True, max_length=100)
#     religion = models.CharField(blank=True, null=True, max_length=100)
#     biography = models.TextField(blank=True, null=True)
#     profile = models.TextField(blank=True, null=True)
#     campaigns = models.TextField(blank=True, null=True)
#     timestamp = models.DateTimeField(blank=True, null=True)
#     if IMAGE_MODEL:
#         photo_fk = models.ForeignKey(
#             get_model(IMAGE_MODEL), 
#             blank=True, 
#             null=True)
#         thumbnail_tk = models.ForeignKey(
#             get_model(IMAGE_MODEL), 
#             blank=True, 
#             null=True)
#     photo = models.FileField(
#         upload_to='elections', 
#         storage=STORAGE_MODEL(),
#         blank=True,
#         null=True)
#     photo_width = models.IntegerField(blank=True, null=True)
#     photo_height = models.IntegerField(blank=True, null=True)
#     thumbnail = models.FileField(
#         upload_to='elections/thumbs/', 
#         storage=STORAGE_MODEL(),
#         blank=True,
#         null=True)
#     thumbnail_width = models.IntegerField(blank=True, null=True)
#     thumbnail_height = models.IntegerField(blank=True, null=True)
# 
#     @property
#     def full_name(self):
#         names =[]
#         if self.first_name:
#             names.append(self.first_name)
#         if self.middle_name:
#             names.append(self.middle_name)
#         if self.last_name:
#             names.append(self.last_name)
#         name = u" ".join(names)
#         if self.junior:
#             name = u"%s, %s" % (name, self.junior)
#         return name
#     
#     @models.permalink
#     def get_absolute_url(self):
#         """
#         Get the absolute url for the candidate
#         """
#         return ('candidate_detail', (), {'slug': self.slug })
#     
#     def save(self, *args, **kwargs):
#         """
#         Make sure the slug is created when imported
#         """
#         if not self.slug:
#             from django.template.defaultfilters import slugify
#             
#             self.slug = slugify("%s %s" % (self.full_name.replace(",", ""), self.politician_id))
#         super(Candidate, self).save(*args, **kwargs)
#     
#     objects = TestDataManager()
#     
#     class Meta:
#         ordering = ('last_name', 'first_name')
#     
#     def __unicode__(self):
#         return self.full_name


import time
import datetime
        import csv
from django.core.management.base import LabelCommand, CommandError
from elections.models import Candidate
            else:
                row[6] = None
            try:
                candidate = Candidate.objects.get(politician_id=row[0])
                if candidate.timestamp != row[20]:
                    candidate.first_name = row[1]
                    candidate.middle_name = row[2]
                    candidate.last_name = row[3]
                    candidate.junior = row[4]
                    candidate.year_first_elected = row[5]
                    candidate.birth_date = row[6]
                    candidate.birth_place = row[7]
                    candidate.birth_state = row[8]
                    candidate.birth_province = row[9]
                    candidate.birth_country = row[10]
                    candidate.residence_place = row[11]
                    candidate.residence_state = row[12]
                    candidate.gender = row[13]
                    candidate.ethnicity = row[14]
                    candidate.hispanic = row[15]
                    candidate.religion = row[16]
                    candidate.biography = row[17]
                    candidate.profile = row[18]
                    candidate.campaigns = row[19]
                    candidate.timestamp = row[20]
                    print 'Updating %s %s' % (row[1], row[3])
                    candidate.save()
                else:
                    print "Skipping %s %s. No change." % (row[1], row[3])
                    

# Path: elections/models.py
# class Candidate(models.Model):
#     """
#     An election candidate
#     """
#     test_flag = TestFlagField()
#     politician_id = models.IntegerField(primary_key=True)
#     slug = models.SlugField()
#     ap_candidate_id = models.IntegerField(unique=True)
#     candidate_number = models.IntegerField()
#     first_name = models.CharField(blank=True, null=True, max_length=64)
#     middle_name = models.CharField(blank=True, null=True, max_length=64)
#     last_name = models.CharField(blank=True, null=True, max_length=64)
#     junior = models.CharField(blank=True, null=True, max_length=16)
#     use_junior = models.BooleanField(default=False)
#     year_first_elected = models.IntegerField(blank=True, null=True)
#     birth_date = models.DateField(blank=True, null=True)
#     birth_place = models.CharField(blank=True, null=True, max_length=100)
#     birth_state = models.CharField(blank=True, null=True, max_length=2)
#     birth_province = models.CharField(blank=True, null=True, max_length=100)
#     birth_country = models.CharField(blank=True, null=True, max_length=100)
#     residence_place = models.CharField(blank=True, null=True, max_length=100)
#     residence_state = models.CharField(blank=True, null=True, max_length=2)
#     gender = models.CharField(
#         blank=True, null=True, 
#         max_length=1, 
#         choices=(('M', 'Male'), ('F', 'Female')))
#     ethnicity = models.CharField(blank=True, null=True, max_length=100)
#     hispanic = models.CharField(blank=True, null=True, max_length=100)
#     religion = models.CharField(blank=True, null=True, max_length=100)
#     biography = models.TextField(blank=True, null=True)
#     profile = models.TextField(blank=True, null=True)
#     campaigns = models.TextField(blank=True, null=True)
#     timestamp = models.DateTimeField(blank=True, null=True)
#     if IMAGE_MODEL:
#         photo_fk = models.ForeignKey(
#             get_model(IMAGE_MODEL), 
#             blank=True, 
#             null=True)
#         thumbnail_tk = models.ForeignKey(
#             get_model(IMAGE_MODEL), 
#             blank=True, 
#             null=True)
#     photo = models.FileField(
#         upload_to='elections', 
#         storage=STORAGE_MODEL(),
#         blank=True,
#         null=True)
#     photo_width = models.IntegerField(blank=True, null=True)
#     photo_height = models.IntegerField(blank=True, null=True)
#     thumbnail = models.FileField(
#         upload_to='elections/thumbs/', 
#         storage=STORAGE_MODEL(),
#         blank=True,
#         null=True)
#     thumbnail_width = models.IntegerField(blank=True, null=True)
#     thumbnail_height = models.IntegerField(blank=True, null=True)
# 
#     @property
#     def full_name(self):
#         names =[]
#         if self.first_name:
#             names.append(self.first_name)
#         if self.middle_name:
#             names.append(self.middle_name)
#         if self.last_name:
#             names.append(self.last_name)
#         name = u" ".join(names)
#         if self.junior:
#             name = u"%s, %s" % (name, self.junior)
#         return name
#     
#     @models.permalink
#     def get_absolute_url(self):
#         """
#         Get the absolute url for the candidate
#         """
#         return ('candidate_detail', (), {'slug': self.slug })
#     
#     def save(self, *args, **kwargs):
#         """
#         Make sure the slug is created when imported
#         """
#         if not self.slug:
#             from django.template.defaultfilters import slugify
#             
#             self.slug = slugify("%s %s" % (self.full_name.replace(",", ""), self.politician_id))
#         super(Candidate, self).save(*args, **kwargs)
#     
#     objects = TestDataManager()
#     
#     class Meta:
#         ordering = ('last_name', 'first_name')
#     
#     def __unicode__(self):
#         return self.full_name


# Path: elections/management/commands/import_bios.py
import time
import datetime
        import csv
from django.core.management.base import LabelCommand, CommandError
from elections.models import Candidate

            else:
                row[6] = None
            try:
                candidate = Candidate.objects.get(politician_id=row[0])
                if candidate.timestamp != row[20]:
                    candidate.first_name = row[1]
                    candidate.middle_name = row[2]
                    candidate.last_name = row[3]
                    candidate.junior = row[4]
                    candidate.year_first_elected = row[5]
                    candidate.birth_date = row[6]
                    candidate.birth_place = row[7]
                    candidate.birth_state = row[8]
                    candidate.birth_province = row[9]
                    candidate.birth_country = row[10]
                    candidate.residence_place = row[11]
                    candidate.residence_state = row[12]
                    candidate.gender = row[13]
                    candidate.ethnicity = row[14]
                    candidate.hispanic = row[15]
                    candidate.religion = row[16]
                    candidate.biography = row[17]
                    candidate.profile = row[18]
                    candidate.campaigns = row[19]
                    candidate.timestamp = row[20]
                    print 'Updating %s %s' % (row[1], row[3])
                    candidate.save()
                else:
                    print "Skipping %s %s. No change." % (row[1], row[3])
                    

            except Candidate.DoesNotExist: