Django/Python rookie. Have a function that isn't finishing when called. No error, it just stops and goes back to the python command prompt. It does the first while loop but stops before it gets to the next 'print' command, and takes me back to the prompt. Everything that executed is correct. I'm sure it's something basic I've missed. here's the function:
def create_carpool(family, start_date, end_date, name):
carpool = Carpool()
carpool.name = name
carpool.save()
current_date = start_date
while current_date <= end_date:
print 'Processing ' + current_date.strftime('%m/%d/%Y') + ' going to ' + end_date.strftime('%m/%d/%Y')
if current_date.day not in (5,6):
start_leg = Leg()
start_leg.drive_date = current_date
start_leg.start_time = START_TIME_AM
start_leg.endpoint = ENDPOINT_AM
start_leg.save()
end_leg = Leg()
end_leg.drive_date = current_date
end_leg.start_time = START_TIME_PM
end_leg.endpoint = ENDPOINT_PM
end_leg.save()
carpool.legs.add(start_leg)
carpool.legs.add(end_leg)
current_date += datetime.timedelta(days=1)
print 'Adding driving preferences for all carpool legs.'
num_legs = carpool.legs.all().count()
leg_idx = 0
for leg in carpool.legs.all():
leg_idx += 1
print 'Processing leg #' + str(leg_idx) + ' of ' + str(num_legs)
for rider in Rider.objects.all():
if choice(number_list) >= 4:
leg.riders.add(rider)
for driver in carpool.drivers.all():
drive_preference = DrivingPreference()
drive_preference.leg = leg
drive_preference.driver = family.drivers
drive_preference.preference = choice([1,2,3])
drive_preference.save()
return carpool