You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.0 KiB

3 years ago
from django.db import models
from apps.base.models import BaseModel
3 years ago
class ProblemType(models.IntegerChoices):
ACM = 0
OI = 1
class ProblemAuth(models.IntegerChoices):
PUBLIC = 0
PRIVATE = 1
CONTEST = 2
class Degree(models.IntegerChoices):
EASY = 0
BASE = 1
MEDIUM = 2
HARD = 3
class VideoStatus(models.IntegerChoices):
PRIVATE = 0
UPLOADING = 1
PUBLIC = 2
class CourseLevel(models.IntegerChoices):
EASY = 0
BASE = 1
Advanced = 2
PRO = 3
class JudgeType(models.TextChoices):
SPJ = "spj"
COMMON = "common"
class ChapterIndex(models.TextChoices):
ONE = "第一章"
TWO = "第二章"
THREE = "第三章"
FOUR = "第四章"
FIVE = "第五章"
SIX = "第六章"
SEVEN = "第七章"
EIGHT = "第八章"
NINE = "第九章"
TEN = "第十章"
ELEVEN = "第十一章"
TWELVE = "第十二章"
class Course(BaseModel):
"""课程模型
"""
title = models.CharField(max_length=50)
description = models.TextField(null=True)
price = models.FloatField(default=0)
cover_img_url = models.CharField(max_length=255)
view_count = models.IntegerField(default=0)
sale_count = models.IntegerField(default=0)
is_active = models.BooleanField(default=True)
# 课程分类,默认为基础
level = models.IntegerField(
choices=CourseLevel.choices, default=CourseLevel.BASE)
class Chapter(BaseModel):
"""章节模型
"""
index = models.CharField(choices=ChapterIndex.choices,max_length=50)
title = models.CharField(max_length=100)
description = models.TextField(null=True)
cover_img_url = models.CharField(max_length=255, default=None)
view_count = models.IntegerField(default=0)
is_active = models.BooleanField(default=True)
course_id = models.ForeignKey(
Course, on_delete=models.CASCADE)
class Lession(BaseModel):
"""节模型
"""
index = models.IntegerField()
title = models.CharField(max_length=100)
is_active = models.BooleanField(default=True)
# 一个章节有多节课,one to many
chapter_id = models.ForeignKey(
Chapter, on_delete=models.CASCADE)
# 一节课一个视频一个视频多节课one to many
# 一节课有多个问题,一个问题有多节课 ,many to many
class Video(BaseModel):
"""视频模型
"""
title = models.CharField(max_length=100)
img_url = models.CharField(max_length=255)
video_url = models.CharField(max_length=255)
count = models.IntegerField(default=0)
is_free = models.BooleanField(default=False)
duration = models.IntegerField() # s
size = models.IntegerField() # kb
status = models.IntegerField(choices=VideoStatus.choices, default=VideoStatus.PUBLIC)
description = models.CharField(max_length=255, null=True)
is_active = models.BooleanField(default=True)
lession = models.OneToOneField(
Lession, on_delete=models.DO_NOTHING)
class Problem(BaseModel):
"""问题模型"""
judge_type = models.CharField(choices=JudgeType.choices, max_length=10, default=JudgeType.COMMON)
problem_id = models.CharField(max_length=20, unique=True)
title = models.CharField(max_length=100)
type = models.IntegerField(choices=ProblemType.choices, default=ProblemType.OI)
time_limit = models.IntegerField(default=1000) # 1000ms
memory_limit = models.IntegerField(default=128) # 128mb
start_limit = models.IntegerField(default=128) # 128mb
description = models.TextField()
input_description = models.TextField()
output_description = models.TextField()
examples = models.TextField()
degree = models.IntegerField(choices=Degree.choices, default=Degree.BASE)
hint = models.TextField(null=True)
auth = models.IntegerField(choices=ProblemAuth.choices, default=ProblemAuth.PUBLIC)
io_score = models.IntegerField(default=100) # 满分100
code_share = models.BooleanField(default=True)
spj_code = models.TextField(null=True)
spj_language = models.CharField(max_length=50, null=True)
is_remove_end_blank = models.BooleanField(default=True)
is_open_case = models.BooleanField(default=True)
is_upload_case = models.BooleanField(default=True)
is_active = models.BooleanField(default=True)
lession_id = models.ForeignKey(Lession, on_delete=models.DO_NOTHING)
class Tag(BaseModel):
"""标签模型"""
name = models.CharField(max_length=50)
status = models.BooleanField(default=True)
# 问题,标签 多对多
problems = models.ManyToManyField(Problem)
class Case(BaseModel):
input = models.TextField()
output = models.TextField()
status = models.BooleanField(default=True)
problem_id = models.ForeignKey(Problem, on_delete=models.CASCADE)
class Meta:
db_table = "case"
class Language(BaseModel):
content_type = models.CharField(max_length=50)
description = models.TextField()
name = models.CharField(max_length=50)
compile_command = models.TextField()
is_spj = models.BooleanField()