From 9871394833e31e793950cdd6158ce0a09aa16311 Mon Sep 17 00:00:00 2001 From: jedi Date: Fri, 14 Jun 2024 20:11:04 +0200 Subject: [PATCH] stash --- .../0011_issuethread_related_items.py | 19 +++++++++++++++++++ core/tickets/models.py | 1 + core/tickets/serializers.py | 10 ++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 core/tickets/migrations/0011_issuethread_related_items.py diff --git a/core/tickets/migrations/0011_issuethread_related_items.py b/core/tickets/migrations/0011_issuethread_related_items.py new file mode 100644 index 0000000..68240bc --- /dev/null +++ b/core/tickets/migrations/0011_issuethread_related_items.py @@ -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'), + ), + ] diff --git a/core/tickets/models.py b/core/tickets/models.py index b6c210f..49fb335 100644 --- a/core/tickets/models.py +++ b/core/tickets/models.py @@ -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] diff --git a/core/tickets/serializers.py b/core/tickets/serializers.py index fe3972e..c76f476 100644 --- a/core/tickets/serializers.py +++ b/core/tickets/serializers.py @@ -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):