scripts/init_news.py
import os
import sys
import django
# 准备
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_dir)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "auction.settings")
django.setup()
from api import models
for i in range(40, 50):
news_obj = models.News.objects.create(
cover='https://person-1313480500.cos.ap-chengdu.myqcloud.com/avatar.jpg',
content='这是{}猫'.format(i),
topic_id=1,
user_id=1
)
models.NewsDetail.objects.bulk_create([
models.NewsDetail(key='2.jpg', cos_path='https://person-1313480500.cos.ap-chengdu.myqcloud.com/2.jpg',
news=news_obj),
models.NewsDetail(key='avatar.jpg', cos_path='https://person-1313480500.cos.ap-chengdu.myqcloud.com/avatar.jpg',
news=news_obj)
])
标签:cos,python,离线,jpg,django,models,news,path,os
From: https://www.cnblogs.com/fuminer/p/16827026.html