File size: 1,452 Bytes
b4f2238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Module for template binding."""

from __future__ import annotations

from typing import ClassVar

from django.db import models
from django.utils.translation import gettext_lazy as _


class BindingSource(models.TextChoices):
    """绑定来源"""

    AUTO_RECOMMENDED = "auto_recommended", _("自动推荐")
    MANUAL_BOUND = "manual_bound", _("手动绑定")


class CaseTemplateBinding(models.Model):
    """案件模板绑定关系"""

    id: int
    case = models.ForeignKey(
        "cases.Case", on_delete=models.CASCADE, related_name="template_bindings", verbose_name=_("案件")
    )
    template = models.ForeignKey(
        "documents.DocumentTemplate", on_delete=models.CASCADE, related_name="case_bindings", verbose_name=_("文书模板")
    )
    binding_source = models.CharField(
        max_length=20, choices=BindingSource.choices, default=BindingSource.AUTO_RECOMMENDED, verbose_name=_("绑定来源")
    )
    created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("绑定时间"))

    class Meta:
        verbose_name = _("案件模板绑定")
        verbose_name_plural = _("案件模板绑定")
        unique_together: ClassVar = ["case", "template"]
        indexes: ClassVar = [
            models.Index(fields=["case", "binding_source"]),
            models.Index(fields=["template"]),
        ]

    def __str__(self) -> str:
        return f"{self.case_id}-{self.template_id}-{self.binding_source}"