use uuid in tickets
This commit is contained in:
parent
4664d6255d
commit
f7002c5548
4 changed files with 51 additions and 4 deletions
|
@ -2,7 +2,7 @@ from django.db import models
|
|||
from django_softdelete.models import SoftDeleteModel
|
||||
|
||||
from inventory.models import Event
|
||||
from django.db.models.signals import post_save
|
||||
from django.db.models.signals import post_save, pre_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
STATE_CHOICES = (
|
||||
|
@ -25,10 +25,14 @@ STATE_CHOICES = (
|
|||
|
||||
class IssueThread(SoftDeleteModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
uuid = models.CharField(max_length=255, unique=True, null=False, blank=False)
|
||||
name = models.CharField(max_length=255)
|
||||
assigned_to = models.CharField(max_length=255, null=True)
|
||||
manually_created = models.BooleanField(default=False)
|
||||
|
||||
def short_uuid(self):
|
||||
return self.uuid[:8]
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
try:
|
||||
|
@ -49,6 +53,13 @@ class IssueThread(SoftDeleteModel):
|
|||
]
|
||||
|
||||
|
||||
@receiver(pre_save, sender=IssueThread)
|
||||
def set_uuid(sender, instance, **kwargs):
|
||||
import uuid
|
||||
if instance.uuid is None or instance.uuid == '':
|
||||
instance.uuid = str(uuid.uuid4())
|
||||
|
||||
|
||||
@receiver(post_save, sender=IssueThread)
|
||||
def create_issue_thread(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue