From b24844831cd372b66574fc200183779f80fe0a8b Mon Sep 17 00:00:00 2001 From: jedi Date: Fri, 19 Jul 2024 21:04:55 +0200 Subject: [PATCH] stash --- core/inventory/serializers.py | 11 ++++++++++- core/inventory/tests/v2/test_events.py | 12 ++++++++++++ core/mail/models.py | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/inventory/serializers.py b/core/inventory/serializers.py index b643eb3..4aef119 100644 --- a/core/inventory/serializers.py +++ b/core/inventory/serializers.py @@ -3,12 +3,21 @@ from rest_framework import serializers from files.models import File from inventory.models import Event, Container, Item +from mail.models import EventAddress + + +class EventAdressSerializer(serializers.ModelSerializer): + class Meta: + model = EventAddress + fields = ['address'] class EventSerializer(serializers.ModelSerializer): + addresses = EventAdressSerializer(many=True, required=False) + class Meta: model = Event - fields = ['eid', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end'] + fields = ['eid', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end', 'addresses'] read_only_fields = ['eid'] diff --git a/core/inventory/tests/v2/test_events.py b/core/inventory/tests/v2/test_events.py index 7973313..affbd0e 100644 --- a/core/inventory/tests/v2/test_events.py +++ b/core/inventory/tests/v2/test_events.py @@ -54,3 +54,15 @@ class EventTestCase(TestCase): response = client.delete(f'/api/2/events/{event.eid}/') self.assertEqual(response.status_code, 204) self.assertEqual(len(Event.objects.all()), 1) + + def test_items2(self): + from mail.models import EventAddress + event1 = Event.objects.create(slug='TEST1', name='Event') + EventAddress.objects.create(event=Event.objects.get(slug='TEST1'), address='foo@bar.baz') + response = self.client.get('/api/2/events/') + self.assertEqual(response.status_code, 200) + self.assertEqual(1, len(response.json())) + self.assertEqual('TEST1', response.json()[0]['slug']) + self.assertEqual('Event', response.json()[0]['name']) + self.assertEqual(1, len(response.json()[0]['addresses'])) + diff --git a/core/mail/models.py b/core/mail/models.py index ca71c88..21061b5 100644 --- a/core/mail/models.py +++ b/core/mail/models.py @@ -32,7 +32,7 @@ class Email(SoftDeleteModel): class EventAddress(models.Model): id = models.AutoField(primary_key=True) - event = models.ForeignKey(Event, models.SET_NULL, null=True) + event = models.ForeignKey(Event, models.SET_NULL, null=True, related_name='addresses') address = models.CharField(max_length=255)