Files
game-cards-poker-design/backend/apps/projects/models.py
Poker Design Developer 0370e4018a Implement asset upload API and utility functions
- Add Asset and CardLayer model updates
- Create asset upload API endpoints
- Add AssetUploadDialog component
- Create card layout algorithms
- Implement symmetry generation utils
- Add template configurations
2026-05-31 15:33:50 +08:00

64 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.db import models
import uuid
class Project(models.Model):
"""项目配置模型"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=100)
template_id = models.CharField(max_length=50, default='classic')
card_width = models.IntegerField(default=750)
card_height = models.IntegerField(default=1050)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
# 导出设置
export_resolution = models.CharField(max_length=20, default='standard')
export_include_back = models.BooleanField(default=True)
def __str__(self):
return self.name
class Meta:
ordering = ['-updated_at']
class Asset(models.Model):
"""项目素材模型"""
project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='assets')
asset_type = models.CharField(max_length=20) # 'suit_symbol', 'face_card', 'joker', 'back', 'border'
asset_key = models.CharField(max_length=50) # 如 'spade', 'heart-J', 'big_joker'
file_path = models.CharField(max_length=255) # 相对于media目录
file_name = models.CharField(max_length=100)
width = models.IntegerField(null=True)
height = models.IntegerField(null=True)
uploaded_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"{self.asset_type}:{self.asset_key}"
class Meta:
ordering = ['-uploaded_at']
class CardLayer(models.Model):
"""牌面图层配置模型"""
project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='layers')
card_type = models.CharField(max_length=20) # 'number', 'face', 'joker'
card_key = models.CharField(max_length=30) # 'spade-A', 'heart-K', 'big_joker'
layer_name = models.CharField(max_length=50)
layer_type = models.CharField(max_length=20) # 'background', 'border', 'image', 'text'
visible = models.BooleanField(default=True)
locked = models.BooleanField(default=False)
opacity = models.FloatField(default=1.0)
z_index = models.IntegerField(default=0)
# 图层属性JSON存储
properties = models.JSONField(default=dict)
def __str__(self):
return f"{self.card_key}-{self.layer_name}"
class Meta:
ordering = ['card_key', 'z_index']