25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
|
from django.db import models
|
||
|
from django.contrib.auth import get_user_model
|
||
|
|
||
|
from apps.models import App
|
||
|
|
||
|
class Panic(models.Model):
|
||
|
created_by_user = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, blank=True, related_name="panics_created")
|
||
|
created_by_app = models.ForeignKey(App, on_delete=models.SET_NULL, null=True, blank=True, related_name="panics_created")
|
||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||
|
create_reason = models.TextField()
|
||
|
resolved_by_user = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, blank=True, related_name="panics_resolved")
|
||
|
resolved_by_app = models.ForeignKey(App, on_delete=models.SET_NULL, null=True, blank=True, related_name="panics_resolved")
|
||
|
resolved_at = models.DateTimeField(null=True, blank=True)
|
||
|
resolve_reason = models.TextField(null=True, blank=True)
|
||
|
|
||
|
def __str__(self):
|
||
|
return f"{self.user.username} at {self.created_at}"
|
||
|
|
||
|
@classmethod
|
||
|
def active(cls):
|
||
|
try:
|
||
|
return cls.objects.get(resolved_at__isnull=True)
|
||
|
except cls.DoesNotExist:
|
||
|
return None
|