add /matches endpoint ad return match information in tickets and /item endpoints
This commit is contained in:
parent
aaa11c3b60
commit
797ea3ae12
12 changed files with 339 additions and 61 deletions
|
@ -1,5 +1,7 @@
|
|||
from django.db import models
|
||||
from itertools import groupby
|
||||
|
||||
from django.utils import timezone
|
||||
from django.db import models
|
||||
from django_softdelete.models import SoftDeleteModel
|
||||
|
||||
from authentication.models import ExtendedUser
|
||||
|
@ -43,7 +45,6 @@ class IssueThread(SoftDeleteModel):
|
|||
name = models.CharField(max_length=255)
|
||||
event = models.ForeignKey(Event, null=True, on_delete=models.SET_NULL, related_name='issue_threads')
|
||||
manually_created = models.BooleanField(default=False)
|
||||
related_items = models.ManyToManyField(Item, through='ItemRelation')
|
||||
|
||||
def short_uuid(self):
|
||||
return self.uuid[:8]
|
||||
|
@ -76,6 +77,11 @@ class IssueThread(SoftDeleteModel):
|
|||
return
|
||||
self.assignments.create(assigned_to=value)
|
||||
|
||||
@property
|
||||
def related_items(self):
|
||||
groups = groupby(self.item_relation_changes.all(), lambda rel: rel.item.id)
|
||||
return [sorted(v, key=lambda r: r.timestamp)[0].item for k, v in groups]
|
||||
|
||||
def __str__(self):
|
||||
return '[' + str(self.id) + '][' + self.short_uuid() + '] ' + self.name
|
||||
|
||||
|
@ -132,8 +138,8 @@ class Assignment(models.Model):
|
|||
|
||||
class ItemRelation(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='item_relations')
|
||||
item = models.ForeignKey(Item, on_delete=models.CASCADE, related_name='issues')
|
||||
issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='item_relation_changes')
|
||||
item = models.ForeignKey(Item, on_delete=models.CASCADE, related_name='issue_relation_changes')
|
||||
timestamp = models.DateTimeField(auto_now_add=True)
|
||||
status = models.CharField(max_length=255, choices=RELATION_STATUS_CHOICES, default='possible')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue