전체 구조

클래스

class ProblemTag(models.Model)

class ProblemTag(models.Model):
    name = models.TextField()

    class Meta:
        db_table = "problem_tag"

class ProblemRuleType(Choices)

class ProblemRuleType(Choices):
    ACM = "ACM"
    OI = "OI"

class ProblemDifficulty(object)

class ProblemDifficulty(object):
    High = "High"
    Mid = "Mid"
    Low = "Low"

class ProblemIOMode(Choices)

class ProblemIOMode(Choices):
    standard = "Standard IO"
    file = "File IO"

def _default_io_mode()

def _default_io_mode():
    return {"io_mode": ProblemIOMode.standard, "input": "input.txt", "output": "output.txt"}

class Problem(models.Model)

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

class Meta:
        db_table = "problem"
        unique_together = (("_id", "contest"),)
        ordering = ("create_time",)

def add_submission_number(self)

def add_submission_number(self):
        self.submission_number = models.F("submission_number") + 1
        self.save(update_fields=["submission_number"])

def add_ac_number(self)

def add_ac_number(self):
        self.accepted_number = models.F("accepted_number") + 1
        self.save(update_fields=["accepted_number"])

찾아본 것들

중첩 클래스

Python의 중첩 클래스

메타 클래스 - 메타 옵션 정리

Django 모델의 메타 클래스

메타 클래스에 대해서

모델 메타 옵션

메타 클래스 옵션에 대해서

위키독스

Field 클래스

예제로 배우는 파이썬 프로그래밍 - Django 모델 (Model)

Untitled

Django Model이란

Django 기본 05 - 모델(Model), 모델필드, 필드옵션

필드(Fields) - 데이터베이스

Django Tutorial Part 3: Using models - Web 개발 학습하기 | MDN

F() 객체

Django에서 F() 객체 알아보기

https://www.notion.so/ds-kotlin-study/c83d7dee502041b1b23086ee7873d327#dc7c85c09a4d4614a741e59fcc630c87