# coding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
from django.core.management import BaseCommand

from django.db import connection


class Command(BaseCommand):
    def handle(self, *args, **kwargs):
        cursor = connection.cursor()
        cursor.execute('update api_servicecomment'
                       ' set service_item_id=(select service_item_id '
                       'from api_order where id=order_id)')

        cursor.execute('select service_item_id from api_servicecomment ORDER by id DESC limit 1')
        row = cursor.fetchall()
        print(row)

        cursor = connection.cursor()
        cursor.execute('update api_servicecomment'
                       ' set user_id=(select user_id '
                       'from api_order where id=order_id)')

        cursor.execute('select user_id from api_servicecomment ORDER by id DESC limit 1')
        row = cursor.fetchall()
        print(row)
