from django.core.management.base import BaseCommand from aliyun_video.core import upload_local_video from aliyun_video.models import AliyunVideo class Command(BaseCommand): help = "Upload video to aliyun." def add_arguments(self, parser): parser.add_argument( '--path', required=True, dest='video_path', help='Must be a absolute path.', ) parser.add_argument( '--title', required=True, dest='video_title', help='Video\'s title.', ) parser.add_argument( '--lesson_id', required=True, dest='lesson_id' ) def handle(self, *args, **options): video_id = upload_local_video(options['video_path'], options['video_title']) AliyunVideo.objects.create( video_id=video_id, lesson_id=options['lesson_id'], title=options['video_title'], status=AliyunVideo.STATUS_PROCESSING ) print('Uploaded successfully!')