Skip to content

Instantly share code, notes, and snippets.

@jheasly
Last active September 5, 2016 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jheasly/bee0f8471cd727a7a32cda279f93b6c6 to your computer and use it in GitHub Desktop.
Save jheasly/bee0f8471cd727a7a32cda279f93b6c6 to your computer and use it in GitHub Desktop.
civic_calendar & django-scheduler
'''
Experiments in extending the django_scheduler Event class via the built-in EventRelation class.
'''
>>> from schedule.models import Calendar, Event, EventRelation
>>> from civic_calendar.models import Meeting
>>> event = Event.objects.get(pk=2)
>>> meeting = Meeting.objects.get(pk=2)
>>> er = EventRelation(event=event, content_object=meeting)
>>> er.save()
# The django-scheduler Event side of the EventRelation
>>> er.event
<Event: EWEB meeting: June 21, 2016 - June 21, 2016>
# The civic_calendar Event side of the EventRelation
>>> EventRelation.objects.get_events_for_object(meeting)
[<Event: EWEB meeting: June 21, 2016 - June 21, 2016>]
# Getting the EventRelation instance that has both the Event & Meeting
>>> EventRelation(event=event, content_object=meeting)
<EventRelation: EWEB meeting(None)-Eugene Water & Electric Board>
>>> foo = EventRelation(event=event, content_object=meeting)
>>> dir(foo)
['DoesNotExist', 'MultipleObjectsReturned', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', u'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', '_base_manager', '_check_column_name_clashes', '_check_field_name_clashes', '_check_fields', '_check_id_field', '_check_index_together', '_check_local_fields', '_check_long_column_names', '_check_m2m_through_same_relationship', '_check_managers', '_check_model', '_check_ordering', '_check_swappable', '_check_unique_together', '_content_type_cache', '_default_manager', '_deferred', '_do_insert', '_do_update', '_event_cache', '_get_FIELD_display', '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', '_get_unique_checks', '_meta', '_perform_date_checks', '_perform_unique_checks', '_save_parents', '_save_table', '_set_pk_val', '_state', 'check', 'clean', 'clean_fields', 'content_object', 'content_type', 'content_type_id', 'date_error_message', 'delete', 'distinction', 'event', 'event_id', 'from_db', 'full_clean', 'get_deferred_fields', 'id', 'object_id', 'objects', 'pk', 'prepare_database_save', 'refresh_from_db', 'save', 'save_base', 'serializable_value', 'unique_error_message', 'validate_unique']
>>> foo.event
<Event: EWEB meeting: June 21, 2016 - June 21, 2016>
# The Meeting side of the EventRelation instance ...
>>> foo.content_object
<Meeting: Eugene Water & Electric Board>
>>> foo.content_object.entity
<Entity: Eugene Water & Electric Board>
>>> foo.content_object.entity.name
u'Eugene Water & Electric Board'
# Get the Meeting based upon the Event ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment