# coding=utf-8

from django.core.management import BaseCommand
from api.models import Service, ServiceTag

class Command(BaseCommand):
    """
    python manage.py insert_20180802_xianmeilai
    """

    def handle(self, *args, **kwargs):
        hospital_id = 'd6b4be784a174c11a87869a8d4819aa1'
        tag_ids = [7194, 7222]
        service_ids = Service.objects.filter(
            doctor__hospital_id=hospital_id).values_list('id', flat=True)
        print 'service_ids', service_ids
        for service_id in service_ids:
            for tag_id in tag_ids:
                try:
                    obj = ServiceTag.objects.get_or_create(
                            service_id=service_id,
                            tag_id=tag_id
                    )
                    print obj
                except:
                    print 'error', service_id, tag_id
        print 'Done!'

