This commit is contained in:
j3d1 2024-06-14 20:11:04 +02:00
parent 0a55af3b9d
commit 9871394833
3 changed files with 26 additions and 4 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 4.2.7 on 2024-06-14 17:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('inventory', '0004_alter_event_created_at_alter_item_created_at'),
('tickets', '0010_itemrelation'),
]
operations = [
migrations.AddField(
model_name='issuethread',
name='related_items',
field=models.ManyToManyField(through='tickets.ItemRelation', to='inventory.item'),
),
]

View file

@ -42,6 +42,7 @@ 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]

View file

@ -3,6 +3,7 @@ from rest_framework import serializers
from authentication.models import ExtendedUser
from mail.api_v2 import AttachmentSerializer
from tickets.models import IssueThread, Comment, STATE_CHOICES
from inventory.serializers import ItemSerializer
class CommentSerializer(serializers.ModelSerializer):
@ -33,18 +34,19 @@ class IssueSerializer(serializers.ModelSerializer):
last_activity = serializers.SerializerMethodField()
assigned_to = serializers.SlugRelatedField(slug_field='username', queryset=ExtendedUser.objects.all(),
allow_null=True, required=False)
related_items = ItemSerializer(many=True, read_only=True)
class Meta:
model = IssueThread
fields = ('id', 'timeline', 'name', 'state', 'assigned_to', 'last_activity', 'uuid')
read_only_fields = ('id', 'timeline', 'last_activity', 'uuid')
fields = ('id', 'timeline', 'name', 'state', 'assigned_to', 'last_activity', 'uuid', 'related_items')
read_only_fields = ('id', 'timeline', 'last_activity', 'uuid', 'related_items')
def to_internal_value(self, data):
ret = super().to_internal_value(data)
if 'state' in data:
ret['state'] = data['state']
# if 'assigned_to' in data:
# ret['assigned_to'] = data['assigned_to']
# if 'assigned_to' in data:
# ret['assigned_to'] = data['assigned_to']
return ret
def validate(self, attrs):