mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
feat: update letter patch to check for type change to sent and auto set time
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import uuid
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
@@ -39,6 +40,16 @@ class Letter(models.Model):
|
||||
if self.type == Letter.Type.VAULT and self.status == Letter.Status.SEALED and not self.unlock_at:
|
||||
raise ValidationError("A sealed VAULT letter must have an unlock_date.")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
Override save method to auto set BURNED and SEALED timestamps.
|
||||
"""
|
||||
if self.status == Letter.Status.BURNED:
|
||||
self.burned_at = datetime.now(UTC)
|
||||
if self.status == Letter.Status.SEALED:
|
||||
self.sealed_at = datetime.now(UTC)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.type} - {self.status}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user