class ProblemTag(models.Model):
name = models.TextField()
class Meta:
db_table = "problem_tag"
class ProblemRuleType(Choices):
ACM = "ACM"
OI = "OI"
class ProblemDifficulty(object):
High = "High"
Mid = "Mid"
Low = "Low"
class ProblemIOMode(Choices):
standard = "Standard IO"
file = "File IO"
def _default_io_mode():
return {"io_mode": ProblemIOMode.standard, "input": "input.txt", "output": "output.txt"}
class Problem(models.Model):
# display ID
_id = models.TextField(db_index=True)
contest = models.ForeignKey(Contest, null=True, on_delete=models.CASCADE)
# for contest problem
is_public = models.BooleanField(default=False)
title = models.TextField()
# HTML
description = RichTextField()
input_description = RichTextField()
output_description = RichTextField()
# [{input: "test", output: "123"}, {input: "test123", output: "456"}]
samples = JSONField()
test_case_id = models.TextField()
# [{"input_name": "1.in", "output_name": "1.out", "score": 0}]
test_case_score = JSONField()
hint = RichTextField(null=True)
languages = JSONField()
template = JSONField()
create_time = models.DateTimeField(auto_now_add=True)
# we can not use auto_now here
last_update_time = models.DateTimeField(null=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
# ms
time_limit = models.IntegerField()
# MB
memory_limit = models.IntegerField()
# io mode
io_mode = JSONField(default=_default_io_mode)
# special judge related
spj = models.BooleanField(default=False)
spj_language = models.TextField(null=True)
spj_code = models.TextField(null=True)
spj_version = models.TextField(null=True)
spj_compile_ok = models.BooleanField(default=False)
rule_type = models.TextField()
visible = models.BooleanField(default=True)
difficulty = models.TextField()
tags = models.ManyToManyField(ProblemTag)
source = models.TextField(null=True)
# for OI mode
total_score = models.IntegerField(default=0)
submission_number = models.BigIntegerField(default=0)
accepted_number = models.BigIntegerField(default=0)
# {JudgeStatus.ACCEPTED: 3, JudgeStaus.WRONG_ANSWER: 11}, the number means count
statistic_info = JSONField(default=dict)
share_submission = models.BooleanField(default=False)
class Meta:
db_table = "problem"
unique_together = (("_id", "contest"),)
ordering = ("create_time",)
def add_submission_number(self):
self.submission_number = models.F("submission_number") + 1
self.save(update_fields=["submission_number"])
def add_ac_number(self):
self.accepted_number = models.F("accepted_number") + 1
self.save(update_fields=["accepted_number"])
class Meta:
db_table = "problem"
unique_together = (("_id", "contest"),)
ordering = ("create_time",)
problem
이 된다.def add_submission_number(self):
self.submission_number = models.F("submission_number") + 1
self.save(update_fields=["submission_number"])
def add_ac_number(self):
self.accepted_number = models.F("accepted_number") + 1
self.save(update_fields=["accepted_number"])
메타 클래스에 대해서
메타 클래스 옵션에 대해서
db_table = "problem_tag"
problem_tag
가 된다.unique_together
uniqueConstraint
권장ordering
예제로 배우는 파이썬 프로그래밍 - Django 모델 (Model)
Django 기본 05 - 모델(Model), 모델필드, 필드옵션
Django Tutorial Part 3: Using models - Web 개발 학습하기 | MDN
my_field_name = models.CharField(max_length=20, help_text='Enter field documentation')
my_field_name
models.CharField
타입https://www.notion.so/ds-kotlin-study/c83d7dee502041b1b23086ee7873d327#dc7c85c09a4d4614a741e59fcc630c87