Пример #1
0
 def respondent_exists(self, respondentid):
     try:
         respondent_object = People.objects.get(household_id = respondentid, respondent_identifier = 1)
         return respondent_object
     except:
         print("We did not find, so we are creating one")
         respondent_object = People()
         respondent_object.household_id = HouseholdList(household_number = respondentid)
         respondent_object.save()
         return People(household_id = respondentid)
Пример #2
0
 def import_people(self, data, counts = 1000):
     '''Imports people from the roster file'''
     # remove first header row
     data = data[1:]
     counter = 0
     for line in data:
         person = People()
         person.household_id = self.household_exists(line[0])
         person.respondent_identifier = line[1]
         person.age = line[2]
         person.sex = line[4]
         person.relationship_to_respondent = line[3]
         person.save()
         counter += 1
         if counter == counts:
             break