diff --git a/python/cac_tripplanner/default_media/events/CrazyPhiladelphiaEddie_3.jpg b/python/cac_tripplanner/default_media/events/CrazyPhiladelphiaEddie_3.jpg deleted file mode 100644 index 9f0265658..000000000 Binary files a/python/cac_tripplanner/default_media/events/CrazyPhiladelphiaEddie_3.jpg and /dev/null differ diff --git a/python/cac_tripplanner/default_media/events/CrazyPhiladelphiaEddie_5.jpg b/python/cac_tripplanner/default_media/events/CrazyPhiladelphiaEddie_5.jpg deleted file mode 100644 index 512aeaa53..000000000 Binary files a/python/cac_tripplanner/default_media/events/CrazyPhiladelphiaEddie_5.jpg and /dev/null differ diff --git a/python/cac_tripplanner/destinations/admin.py b/python/cac_tripplanner/destinations/admin.py index fa434f8d5..7a14983f3 100644 --- a/python/cac_tripplanner/destinations/admin.py +++ b/python/cac_tripplanner/destinations/admin.py @@ -82,7 +82,7 @@ class EventAdmin(ImageCroppingMixin, admin.ModelAdmin): fields = ('name', 'website_url', 'description', 'image', 'image_raw', 'wide_image', 'wide_image_raw', 'published', 'priority', 'accessible', 'activities', - 'start_date', 'end_date', 'destination') + 'start_date', 'end_date', 'destinations') list_display = ('name', 'published', 'priority', ) actions = ('make_published', 'make_unpublished', ) ordering = ('name', ) diff --git a/python/cac_tripplanner/destinations/forms.py b/python/cac_tripplanner/destinations/forms.py index a822dde51..89fc7c266 100644 --- a/python/cac_tripplanner/destinations/forms.py +++ b/python/cac_tripplanner/destinations/forms.py @@ -35,9 +35,9 @@ class Meta: def __init__(self, *args, **kwargs): super(EventForm, self).__init__(*args, **kwargs) - self.fields['destination'].widget.can_delete_related = False - self.fields['destination'].widget.can_add_related = False - self.fields['destination'].widget.can_change_related = False + self.fields['destinations'].widget.can_delete_related = False + self.fields['destinations'].widget.can_add_related = False + self.fields['destinations'].widget.can_change_related = False def clean(self): """Validate start date is less than end date""" diff --git a/python/cac_tripplanner/destinations/migrations/0047_allow_multiple_event_destinations.py b/python/cac_tripplanner/destinations/migrations/0047_allow_multiple_event_destinations.py new file mode 100644 index 000000000..69e7ec4f4 --- /dev/null +++ b/python/cac_tripplanner/destinations/migrations/0047_allow_multiple_event_destinations.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-07-29 18:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +def move_event_destinations_to_multiple(apps, schema_editor): + """Move event destination to new set of multiple destinations.""" + Event = apps.get_model('destinations', 'Event') + events = Event.objects.all() + for event in events: + if event.destination: + event.destinations.add(event.destination) + event.save() + + +def move_event_destinations_to_single(apps, schema_editor): + """Move event destination from new set of multiple destinations. + + Use the first destination for the event. + """ + Event = apps.get_model('destinations', 'Event') + events = Event.objects.all() + for event in events: + if event.destinations.count() > 0: + event.destination = event.destinations.first() + event.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('destinations', '0046_prepopulate_events'), + ] + + operations = [ + migrations.AddField( + model_name='event', + name='destinations', + field=models.ManyToManyField(blank=True, to='destinations.Destination'), + ), + migrations.RunPython(move_event_destinations_to_multiple, move_event_destinations_to_single), + migrations.RemoveField( + model_name='event', + name='destination', + ), + ] diff --git a/python/cac_tripplanner/destinations/models.py b/python/cac_tripplanner/destinations/models.py index bfb679206..12bab97ff 100644 --- a/python/cac_tripplanner/destinations/models.py +++ b/python/cac_tripplanner/destinations/models.py @@ -190,7 +190,7 @@ class Meta: start_date = models.DateTimeField() end_date = models.DateTimeField() - destination = models.ForeignKey('Destination', on_delete=models.SET_NULL, null=True, blank=True) + destinations = models.ManyToManyField('Destination', blank=True) objects = EventManager() diff --git a/python/cac_tripplanner/destinations/views.py b/python/cac_tripplanner/destinations/views.py index 86fc22c23..d6a9b153f 100644 --- a/python/cac_tripplanner/destinations/views.py +++ b/python/cac_tripplanner/destinations/views.py @@ -257,11 +257,13 @@ def set_event_properties(event): extra_images = ExtraEventPicture.objects.filter(event=event) obj = set_attraction_properties(obj, event, extra_images) - # add properties of related destination, if any - obj = set_location_properties(obj, event.destination) + # add properties of first related destination, if any + obj = set_location_properties(obj, event.destinations.first()) - # if related destination belongs to Watershed Alliance, so does this event - obj['watershed_alliance'] = event.destination.watershed_alliance if event.destination else False + obj['destinations'] = [set_destination_properties(x) for x in event.destinations.all()] + + # if the first related destination belongs to Watershed Alliance, so does this event + obj['watershed_alliance'] = event.destinations.first().watershed_alliance if event.destinations.count() else False return obj