365 lines
16 KiB
Python
365 lines
16 KiB
Python
from django.core.management.base import BaseCommand
|
|
from django.utils import timezone
|
|
from apps.daren_detail.models import (
|
|
CollaborationMetrics, VideoMetrics, LiveMetrics, CreatorProfile,
|
|
CreatorCampaign, BrandCampaign, CreatorVideo, FollowerMetrics,
|
|
TrendMetrics, PublicCreatorPool, PrivateCreatorPool, PrivateCreatorRelation
|
|
)
|
|
from apps.expertproducts.models import Product as ExpertProduct, Creator as ExpertCreator, Negotiation, Message
|
|
from apps.discovery.models import SearchSession, Creator as DiscoveryCreator
|
|
from apps.brands.models import Brand, Product as BrandProduct, Campaign, BrandChatSession
|
|
from apps.template.models import TemplateCategory, Template
|
|
from apps.user.models import User
|
|
import random
|
|
from datetime import datetime, timedelta
|
|
import uuid
|
|
|
|
class Command(BaseCommand):
|
|
help = '填充测试数据到所有相关模型'
|
|
|
|
def handle(self, *args, **kwargs):
|
|
self.stdout.write('开始填充数据...')
|
|
|
|
# 创建用户(避免重复)
|
|
user, created = User.objects.get_or_create(
|
|
email='test@example.com',
|
|
defaults={
|
|
'password': 'testpassword',
|
|
'company': '测试公司',
|
|
'name': '测试用户',
|
|
'is_first_login': False,
|
|
'last_login': timezone.now()
|
|
}
|
|
)
|
|
|
|
# 创建品牌(避免重复)
|
|
brands = []
|
|
brand_names = ['U品牌', 'R品牌', 'X品牌', 'Q品牌', 'A品牌', 'M品牌']
|
|
for name in brand_names:
|
|
brand, _ = Brand.objects.get_or_create(
|
|
name=name,
|
|
defaults={
|
|
'description': f'{name}的描述信息',
|
|
'logo_url': f'https://example.com/logos/{name}.png',
|
|
'category': '电子产品',
|
|
'source': '内部',
|
|
'collab_count': random.randint(5, 20),
|
|
'creators_count': random.randint(10, 50),
|
|
'campaign_id': str(uuid.uuid4()),
|
|
'total_gmv_achieved': random.randint(10000, 100000),
|
|
'total_views_achieved': random.randint(100000, 1000000),
|
|
'shop_overall_rating': round(random.uniform(3.5, 5.0), 1),
|
|
'dataset_id_list': [str(uuid.uuid4()) for _ in range(3)]
|
|
}
|
|
)
|
|
brands.append(brand)
|
|
|
|
# 创建品牌产品(避免重复)
|
|
products = []
|
|
for brand in brands:
|
|
for i in range(3):
|
|
product, _ = BrandProduct.objects.get_or_create(
|
|
brand=brand,
|
|
name=f'{brand.name}产品{i+1}',
|
|
defaults={
|
|
'description': f'{brand.name}产品{i+1}的详细描述',
|
|
'image_url': f'https://example.com/products/{brand.name}_{i+1}.jpg',
|
|
'pid': f'PID_{uuid.uuid4().hex[:8]}',
|
|
'commission_rate': random.uniform(5, 20),
|
|
'open_collab': random.uniform(10, 30),
|
|
'available_samples': random.randint(10, 100),
|
|
'sales_price_min': random.uniform(100, 500),
|
|
'sales_price_max': random.uniform(500, 2000),
|
|
'stock': random.randint(100, 1000),
|
|
'items_sold': random.randint(50, 500),
|
|
'product_rating': round(random.uniform(3.5, 5.0), 1),
|
|
'reviews_count': random.randint(10, 100),
|
|
'collab_creators': random.randint(5, 20),
|
|
'tiktok_shop': random.choice([True, False]),
|
|
'dataset_id': str(uuid.uuid4())
|
|
}
|
|
)
|
|
products.append(product)
|
|
|
|
# 创建活动(避免重复)
|
|
campaigns = []
|
|
for brand in brands:
|
|
campaign, _ = Campaign.objects.get_or_create(
|
|
brand=brand,
|
|
name=f'{brand.name}活动',
|
|
defaults={
|
|
'description': f'{brand.name}的活动描述',
|
|
'image_url': f'https://example.com/campaigns/{brand.name}.jpg',
|
|
'service': '直播带货',
|
|
'creator_type': 'KOL',
|
|
'creator_level': 'L3',
|
|
'creator_category': '电子产品',
|
|
'creators_count': random.randint(5, 20),
|
|
'gmv': '10000-50000',
|
|
'followers': '10000-100000',
|
|
'views': '100000-1000000',
|
|
'budget': '5000-20000',
|
|
'start_date': timezone.now(),
|
|
'end_date': timezone.now() + timedelta(days=30),
|
|
'dataset_id': str(uuid.uuid4()),
|
|
'status': 'in_progress',
|
|
'gmv_achieved': '25000',
|
|
'views_achieved': '500000',
|
|
'video_link': 'https://example.com/videos/campaign.mp4'
|
|
}
|
|
)
|
|
campaign.link_product.set(random.sample(products, 2))
|
|
campaigns.append(campaign)
|
|
|
|
# 创建创作者档案
|
|
creators = []
|
|
for i in range(10):
|
|
creator = CreatorProfile.objects.create(
|
|
name=f'创作者{i+1}',
|
|
avatar_url=f'https://example.com/avatars/creator_{i+1}.jpg',
|
|
email=f'creator{i+1}@example.com',
|
|
instagram=f'creator{i+1}',
|
|
tiktok_link=f'https://tiktok.com/@{i+1}',
|
|
location='上海',
|
|
live_schedule='每周一、三、五 20:00-22:00',
|
|
category=random.choice([c[0] for c in CreatorProfile.CATEGORY_CHOICES]),
|
|
e_commerce_level=random.randint(1, 7),
|
|
exposure_level=random.choice([e[0] for e in CreatorProfile.EXPOSURE_LEVEL_CHOICES]),
|
|
followers=random.randint(10000, 1000000),
|
|
gmv=random.uniform(10000, 1000000),
|
|
items_sold=random.uniform(1000, 10000),
|
|
avg_video_views=random.randint(10000, 100000),
|
|
pricing_min=random.uniform(1000, 5000),
|
|
pricing_max=random.uniform(5000, 20000),
|
|
pricing_package='基础套餐',
|
|
collab_count=random.randint(5, 50),
|
|
latest_collab='最新合作项目',
|
|
e_commerce_platforms=['TikTok', 'Instagram'],
|
|
gmv_by_channel={'TikTok': 60, 'Instagram': 40},
|
|
gmv_by_category={'电子产品': 70, '服装': 30},
|
|
mcn='知名MCN机构'
|
|
)
|
|
creators.append(creator)
|
|
|
|
# 创建协作指标
|
|
for creator in creators:
|
|
CollaborationMetrics.objects.create(
|
|
avg_commission_rate=random.uniform(5, 20),
|
|
products_count=random.randint(10, 50),
|
|
brand_collaborations=random.randint(5, 20),
|
|
min_product_price=random.uniform(100, 500),
|
|
max_product_price=random.uniform(500, 2000),
|
|
start_date=timezone.now().date(),
|
|
end_date=timezone.now().date() + timedelta(days=30),
|
|
creator=creator
|
|
)
|
|
|
|
# 创建视频指标
|
|
for creator in creators:
|
|
for video_type in ['regular', 'shoppable']:
|
|
VideoMetrics.objects.create(
|
|
video_type=video_type,
|
|
gpm=random.uniform(100, 1000),
|
|
videos_count=random.randint(10, 50),
|
|
avg_views=random.uniform(10000, 100000),
|
|
avg_engagement=random.uniform(1, 10),
|
|
avg_likes=random.randint(1000, 10000),
|
|
start_date=timezone.now().date(),
|
|
end_date=timezone.now().date() + timedelta(days=30),
|
|
creator=creator
|
|
)
|
|
|
|
# 创建直播指标
|
|
for creator in creators:
|
|
for live_type in ['regular', 'shoppable']:
|
|
LiveMetrics.objects.create(
|
|
live_type=live_type,
|
|
gpm=random.uniform(100, 1000),
|
|
lives_count=random.randint(5, 20),
|
|
avg_views=random.uniform(10000, 100000),
|
|
avg_engagement=random.uniform(1, 10),
|
|
avg_likes=random.randint(1000, 10000),
|
|
start_date=timezone.now().date(),
|
|
end_date=timezone.now().date() + timedelta(days=30),
|
|
creator=creator
|
|
)
|
|
|
|
# 创建创作者视频
|
|
for creator in creators:
|
|
for i in range(3):
|
|
CreatorVideo.objects.create(
|
|
creator=creator,
|
|
title=f'视频标题{i+1}',
|
|
description=f'视频描述{i+1}',
|
|
thumbnail_url=f'https://example.com/thumbnails/video_{i+1}.jpg',
|
|
video_url=f'https://example.com/videos/video_{i+1}.mp4',
|
|
video_id=f'VID_{uuid.uuid4().hex[:8]}',
|
|
video_type=random.choice(['regular', 'product']),
|
|
badge=random.choice(['red', 'gold']),
|
|
view_count=random.randint(10000, 100000),
|
|
like_count=random.randint(1000, 10000),
|
|
comment_count=random.randint(100, 1000),
|
|
has_product=random.choice([True, False]),
|
|
product_name=f'产品{i+1}' if random.choice([True, False]) else None,
|
|
product_url=f'https://example.com/products/{i+1}' if random.choice([True, False]) else None,
|
|
release_date=timezone.now().date()
|
|
)
|
|
|
|
# 创建粉丝指标
|
|
for creator in creators:
|
|
FollowerMetrics.objects.create(
|
|
creator=creator,
|
|
start_date=timezone.now().date(),
|
|
end_date=timezone.now().date() + timedelta(days=30),
|
|
female_percentage=random.uniform(40, 60),
|
|
male_percentage=random.uniform(40, 60),
|
|
age_18_24_percentage=random.uniform(20, 40),
|
|
age_25_34_percentage=random.uniform(30, 50),
|
|
age_35_44_percentage=random.uniform(10, 30),
|
|
age_45_54_percentage=random.uniform(5, 15),
|
|
age_55_plus_percentage=random.uniform(1, 10),
|
|
location_data={
|
|
'上海': random.uniform(10, 30),
|
|
'北京': random.uniform(10, 30),
|
|
'广州': random.uniform(5, 20),
|
|
'深圳': random.uniform(5, 20),
|
|
'杭州': random.uniform(5, 15)
|
|
}
|
|
)
|
|
|
|
# 创建趋势指标
|
|
for creator in creators:
|
|
for i in range(10):
|
|
TrendMetrics.objects.create(
|
|
creator=creator,
|
|
date=timezone.now().date() - timedelta(days=i),
|
|
gmv=random.uniform(1000, 10000),
|
|
items_sold=random.randint(100, 1000),
|
|
followers_count=random.randint(10000, 100000),
|
|
video_views=random.randint(10000, 100000),
|
|
engagement_rate=random.uniform(1, 10)
|
|
)
|
|
|
|
# 创建公有达人库
|
|
for creator in creators:
|
|
PublicCreatorPool.objects.create(
|
|
creator=creator,
|
|
category=creator.category,
|
|
remark=f'备注信息:{creator.name}的详细信息'
|
|
)
|
|
|
|
# 创建私有达人库(避免重复)
|
|
private_pool, _ = PrivateCreatorPool.objects.get_or_create(
|
|
user=user,
|
|
name='我的收藏',
|
|
defaults={
|
|
'description': '收藏的达人列表',
|
|
'is_default': True
|
|
}
|
|
)
|
|
|
|
# 创建私有达人关联
|
|
for creator in random.sample(creators, 5):
|
|
PrivateCreatorRelation.objects.create(
|
|
private_pool=private_pool,
|
|
creator=creator,
|
|
added_from_public=True,
|
|
notes=f'关于{creator.name}的笔记',
|
|
status=random.choice(['active', 'archived', 'favorite'])
|
|
)
|
|
|
|
# 创建专家产品
|
|
expert_products = []
|
|
for i in range(10):
|
|
p = ExpertProduct.objects.create(
|
|
name=f'专家产品{i+1}',
|
|
category='电子产品',
|
|
max_price=random.uniform(1000, 5000),
|
|
min_price=random.uniform(500, 1000),
|
|
description=f'专家产品{i+1}的详细描述'
|
|
)
|
|
expert_products.append(p)
|
|
|
|
# 创建专家创作者
|
|
expert_creators = []
|
|
for i in range(10):
|
|
c = ExpertCreator.objects.create(
|
|
name=f'专家创作者{i+1}',
|
|
sex=random.choice(['男', '女']),
|
|
age=random.randint(18, 45),
|
|
category='带货类',
|
|
followers=random.randint(10000, 1000000)
|
|
)
|
|
expert_creators.append(c)
|
|
|
|
# 创建谈判记录
|
|
for i in range(10):
|
|
negotiation = Negotiation.objects.create(
|
|
creator=expert_creators[i],
|
|
product=expert_products[i],
|
|
status=random.choice(['brand_review', 'price_negotiation', 'contract_review']),
|
|
current_round=random.randint(1, 5),
|
|
context={'current_price': random.uniform(500, 2000)}
|
|
)
|
|
|
|
# 为每个谈判创建消息
|
|
for j in range(3):
|
|
Message.objects.create(
|
|
negotiation=negotiation,
|
|
role=random.choice(['user', 'assistant']),
|
|
content=f'谈判消息{j+1}',
|
|
stage=negotiation.status
|
|
)
|
|
|
|
# 创建搜索会话
|
|
for i in range(10):
|
|
session = SearchSession.objects.create(
|
|
session_number=i+1,
|
|
creator_count=random.randint(5, 20),
|
|
shoppable_creators=random.randint(2, 10),
|
|
avg_followers=random.uniform(10000, 100000),
|
|
avg_gmv=random.uniform(10000, 100000),
|
|
avg_video_views=random.uniform(10000, 100000)
|
|
)
|
|
|
|
# 为每个会话创建创作者
|
|
for j in range(5):
|
|
DiscoveryCreator.objects.create(
|
|
session=session,
|
|
name=f'发现创作者{j+1}',
|
|
avatar=f'https://example.com/avatars/discovery_{j+1}.jpg',
|
|
category=random.choice([c[0] for c in DiscoveryCreator.CATEGORIES]),
|
|
ecommerce_level=random.choice([l[0] for l in DiscoveryCreator.ECOMMERCE_LEVELS]),
|
|
exposure_level=random.choice([l[0] for l in DiscoveryCreator.EXPOSURE_LEVELS]),
|
|
followers=random.uniform(10000, 1000000),
|
|
gmv=random.uniform(10000, 100000),
|
|
items_sold=random.uniform(1000, 10000),
|
|
avg_video_views=random.uniform(10000, 100000),
|
|
has_ecommerce=random.choice([True, False]),
|
|
tiktok_url=f'https://tiktok.com/@{j+1}'
|
|
)
|
|
|
|
# 创建模板分类
|
|
categories = []
|
|
for i in range(5):
|
|
category = TemplateCategory.objects.create(
|
|
name=f'模板分类{i+1}',
|
|
description=f'模板分类{i+1}的描述'
|
|
)
|
|
categories.append(category)
|
|
|
|
# 创建模板
|
|
for category in categories:
|
|
for i in range(2):
|
|
Template.objects.create(
|
|
title=f'模板{i+1}',
|
|
content=f'这是模板{i+1}的详细内容,包含了很多有用的信息。',
|
|
category=category,
|
|
mission=random.choice([m[0] for m in Template.MISSION_CHOICES]),
|
|
platform=random.choice([p[0] for p in Template.PLATFORM_CHOICES]),
|
|
collaboration_type=random.choice([c[0] for c in Template.COLLABORATION_CHOICES]),
|
|
service=random.choice([s[0] for s in Template.SERVICE_CHOICES]),
|
|
is_public=random.choice([True, False])
|
|
)
|
|
|
|
self.stdout.write(self.style.SUCCESS('数据填充完成!')) |