#! /usr/bin/env python
# -*- coding: utf-8 -*-
# create by oldman
# Date: 2019/4/29
from django.core.management import BaseCommand

from api.models import ServiceRegister, Service


class Command(BaseCommand):
    """
    美购和美购注册关联商户
    python manage.py update_2019_04_29_service_merchant
    """
    def handle(self, *args, **options):
        for item in ServiceRegister.objects.all():
            try:
                do = item.doctor
                merchant = do.merchant
                item.merchant_id = merchant.id
                item.save()
            except Exception as e:
                print(e.message)
                continue

        for item in Service.objects.all():
            try:
                do = item.doctor
                merchant = do.merchant
                item.merchant_id = merchant.id
                item.save()
            except Exception as e:
                print(e.message)
                continue

