This commit is contained in:
j3d1 2024-07-19 21:04:55 +02:00
parent fe2f8b3b05
commit 37da5b38b1
3 changed files with 23 additions and 2 deletions

View file

@ -3,12 +3,21 @@ from rest_framework import serializers
from files.models import File from files.models import File
from inventory.models import Event, Container, Item 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): class EventSerializer(serializers.ModelSerializer):
addresses = EventAdressSerializer(many=True, required=False)
class Meta: class Meta:
model = Event 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'] read_only_fields = ['eid']

View file

@ -54,3 +54,15 @@ class EventTestCase(TestCase):
response = client.delete(f'/api/2/events/{event.eid}/') response = client.delete(f'/api/2/events/{event.eid}/')
self.assertEqual(response.status_code, 204) self.assertEqual(response.status_code, 204)
self.assertEqual(len(Event.objects.all()), 1) 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']))

View file

@ -32,7 +32,7 @@ class Email(SoftDeleteModel):
class EventAddress(models.Model): class EventAddress(models.Model):
id = models.AutoField(primary_key=True) 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) address = models.CharField(max_length=255)