#!/usr/bin/env python
# encoding=utf-8

from django.core.management import BaseCommand
from api.models import PhoneServiceRecord, Doctor


class Command(BaseCommand):

    def handle(self, *args, **options):
        phone_services = PhoneServiceRecord.objects.filter(doctor__isnull=True)
        for phone_service in phone_services:
            try:
                print "phone_service id:", phone_service.id,
                doctor = Doctor.objects.get(phone_ext=phone_service.transfer_phone)
                print "doctor id:", doctor.id
                phone_service.doctor = doctor
                phone_service.save()
            except:
                print ""
