Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/kak/multiple event destinations#1107 #1128

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- 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='destination',
name='event_only',
field=models.BooleanField(default=False, help_text=b'\n Should this location only appear with its associated event(s)?'),
),
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',
),
]
4 changes: 3 additions & 1 deletion python/cac_tripplanner/destinations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class Meta:
city = models.CharField(max_length=40, default='Philadelphia')
state = models.CharField(max_length=20, default='PA')
zipcode = models.CharField(max_length=5, null=True)
event_only = models.BooleanField(default=False, help_text="""
Should this location only appear with its associated event(s)?""")

# In the admin interface, display the address right above the map, since it triggers geocoding
address = models.CharField(max_length=40, null=True,
Expand Down Expand Up @@ -190,7 +192,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()

Expand Down