from django.db import models from django.utils import timezone from django.conf import settings class CertificateIssuance(models.Model): class Source(models.IntegerChoices): TLMS = 0 LAB = 1 MANUAL = 2 recipient = models.ForeignKey("labs.CertificateRecipient", on_delete=models.CASCADE) cert_type = models.ForeignKey("labs.CertificateType", on_delete=models.CASCADE) cert_number = models.CharField(max_length=32, unique=True, db_collation="utf8mb4_0900_ai_ci") cert_snapshot = models.JSONField( default=dict, help_text=( "The snapshot of the certificate. It is used to generate the certificate PDF. " "Contains the recipient's name, the certificate type...." ), ) issued_at = models.DateTimeField(default=timezone.now) file_storage_provider = models.CharField(max_length=16, null=True, blank=True) file_bucket = models.CharField(max_length=32, null=True, blank=True) file_object_key = models.CharField(max_length=255, null=True, blank=True) file_content_type = models.CharField(max_length=64, null=True, blank=True) tlms_course_id = models.CharField(max_length=32, null=True, blank=True) source = models.IntegerField(choices=Source.choices, default=Source.TLMS) class Meta: db_table = "certificate_issuances" def get_file_public_url(self) -> str: return f"{settings.ALIYUN_CDN_URL}/{self.file_object_key}"