add links between items and tickets /tickets endpoint
This commit is contained in:
parent
d8be7f09e4
commit
2ece0cefd8
5 changed files with 81 additions and 7 deletions
|
@ -3,7 +3,7 @@ from django.utils import timezone
|
|||
from django_softdelete.models import SoftDeleteModel
|
||||
|
||||
from authentication.models import ExtendedUser
|
||||
from inventory.models import Event
|
||||
from inventory.models import Event, Item
|
||||
from django.db.models.signals import post_save, pre_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
|
@ -29,12 +29,21 @@ STATE_CHOICES = (
|
|||
('found_closed', 'Item Found and stored externally and closed'),
|
||||
)
|
||||
|
||||
RELATION_STATUS_CHOICES = (
|
||||
('possible', 'Possible'),
|
||||
('confirmed', 'Confirmed'),
|
||||
('discarded', 'Discarded'),
|
||||
('provided', 'Provided'),
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
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]
|
||||
|
@ -119,6 +128,17 @@ class Assignment(models.Model):
|
|||
return str(self.issue_thread) + ' assigned to ' + self.assigned_to.username
|
||||
|
||||
|
||||
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')
|
||||
timestamp = models.DateTimeField(auto_now_add=True)
|
||||
status = models.CharField(max_length=255, choices=RELATION_STATUS_CHOICES, default='possible')
|
||||
|
||||
def __str__(self):
|
||||
return str(self.issue_thread) + ' related to ' + str(self.item)
|
||||
|
||||
|
||||
class ShippingVoucher(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='shipping_vouchers', null=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue