89 lines
3.4 KiB
Python
89 lines
3.4 KiB
Python
import os
|
|
import django
|
|
import random
|
|
from datetime import datetime, timedelta
|
|
import sys
|
|
|
|
# 添加项目根目录到Python路径
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
# 设置Django环境
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'daren.settings')
|
|
django.setup()
|
|
|
|
from apps.daren_detail.models import CreatorProfile
|
|
|
|
def generate_test_data():
|
|
# 类别列表
|
|
categories = [choice[0] for choice in CreatorProfile.CATEGORY_CHOICES]
|
|
|
|
# 曝光等级列表
|
|
exposure_levels = [choice[0] for choice in CreatorProfile.EXPOSURE_LEVEL_CHOICES]
|
|
|
|
# 电商平台列表
|
|
e_commerce_platforms = ["SUNLINK", "ARZOPA", "BELIFE", "TIKTOK", "SHOPEE", "LAZADA"]
|
|
|
|
# 生成50个测试数据
|
|
for i in range(50):
|
|
# 随机生成GMV (1-2000k)
|
|
gmv = random.randint(1, 2000)
|
|
|
|
# 随机生成粉丝数 (1k-1000k)
|
|
followers = random.randint(1000, 1000000)
|
|
|
|
# 随机生成平均视频观看量 (100-500k)
|
|
avg_views = random.randint(100, 500000)
|
|
|
|
# 随机生成售出商品数量 (100-10000)
|
|
items_sold = random.randint(100, 10000)
|
|
|
|
# 随机生成合作次数 (0-50)
|
|
collab_count = random.randint(0, 50)
|
|
|
|
# 随机生成最新合作时间
|
|
latest_collab = (datetime.now() - timedelta(days=random.randint(0, 365))).strftime("%Y-%m-%d")
|
|
|
|
# 随机选择2-4个电商平台
|
|
selected_platforms = random.sample(e_commerce_platforms, random.randint(2, 4))
|
|
|
|
# 创建达人信息
|
|
creator = CreatorProfile.objects.create(
|
|
name=f"测试达人{i+1}",
|
|
avatar_url=f"https://example.com/avatar{i+1}.jpg",
|
|
is_active=random.choice([True, False]),
|
|
email=f"creator{i+1}@example.com",
|
|
instagram=f"creator{i+1}",
|
|
tiktok_link=f"https://tiktok.com/@creator{i+1}",
|
|
location=random.choice(["北京", "上海", "广州", "深圳", "杭州"]),
|
|
live_schedule="每周一、三、五 20:00-22:00",
|
|
category=random.choice(categories),
|
|
e_commerce_level=random.randint(1, 7),
|
|
exposure_level=random.choice(exposure_levels),
|
|
followers=followers,
|
|
gmv=gmv,
|
|
items_sold=items_sold,
|
|
avg_video_views=avg_views,
|
|
pricing_individual=f"${random.randint(100, 1000)}/video",
|
|
pricing_package=f"${random.randint(1000, 5000)}/package",
|
|
collab_count=collab_count,
|
|
latest_collab=latest_collab,
|
|
e_commerce_platforms=selected_platforms,
|
|
gmv_by_channel={
|
|
"TikTok": random.randint(30, 70),
|
|
"Instagram": random.randint(20, 50),
|
|
"Facebook": random.randint(10, 30)
|
|
},
|
|
gmv_by_category={
|
|
"服装": random.randint(20, 40),
|
|
"美妆": random.randint(15, 35),
|
|
"数码": random.randint(10, 30),
|
|
"家居": random.randint(5, 25)
|
|
},
|
|
mcn=random.choice(["MCN机构A", "MCN机构B", "MCN机构C", None])
|
|
)
|
|
print(f"已创建达人: {creator.name}")
|
|
|
|
if __name__ == "__main__":
|
|
print("开始生成测试数据...")
|
|
generate_test_data()
|
|
print("测试数据生成完成!") |