Skip to content

Instantly share code, notes, and snippets.

@paulmwatson
Created April 20, 2021 09:01
Show Gist options
  • Save paulmwatson/c9e2a15376c3c4c6447ab3367e51545f to your computer and use it in GitHub Desktop.
Save paulmwatson/c9e2a15376c3c4c6447ab3367e51545f to your computer and use it in GitHub Desktop.
Copies an IDP event and its actions.
from idp_data.idp_data.models import Event, EventAction
id = '103'
original_event = Event.objects.get(pk=id)
new_event = Event.objects.get(pk=id)
new_event.pk = None
new_event.id = None
new_event._state.adding = True
new_event.save()
new_event.title = f'{original_event.title} - {new_event.id}'
new_event.save()
for action in original_event.actions.all():
action.pk = None
action.id = None
action.event = new_event
action._state.adding = True
action.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment