models — Swingtime Object Model Definitions¶
Functions¶
create_event¶
-
models.create_event(title, event_type[, description, start_time, end_time, note, **rrule_params])¶ Convenience function to create an
Event, optionally create anEventType, and associatedOccurrenceinstances.Occurrencecreation rules match those forEvent.add_occurrences().Returns the newly created
Eventinstance.Parameters
event_type- can be either an
EventTypeobject or 2-tuple of(abbreviation,label), from which anEventTypeis either created or retrieved. description- sets the event’s description if not
None start_time- will default to the current hour if
None end_time- will default to
start_timeplusswingtime_settings.DEFAULT_OCCURRENCE_DURATIONhour ifNone note- if not
None, add aNoteinstance to the new event rrule_params- follows the
dateutilsAPI (see http://labix.org/python-dateutil)
Example:
from datetime import datetime, time from swingtime import models as swingtime from dateutil import rrule event = swingtime.create_event( 'Beginner Class', ('bgn', 'Beginner Classes'), description='Open to all beginners', start_time=datetime.combine(datetime.now().date(), time(19)), count=6, byweekday=(rrule.MO, rrule.WE, rrule.FR) )
Classes¶
Note¶
EventType¶
Event¶
-
class
models.Event(django.db.models.Model)¶ Container model for general metadata and associated
Occurrenceentries.-
title¶ models.CharField
-
description¶ models.CharField
-
event_type¶ models.ForeignKey for
EventType
-
notes¶ generic.GenericRelation for
Note
-
get_absolute_url()¶ return (‘swingtime-event’, [str(self.id)])
-
add_occurrences(start_time, end_time[, **rrule_params])¶ Add one or more occurences to the event using a comparable API to
dateutil.rrule.If
rrule_paramsdoes not contain afreq, one will be defaulted torrule.DAILY.Because
rrule.rrulereturns an iterator that can essentially be unbounded, we need to slightly alter the expected behavior here in order to enforce a finite number of occurrence creation.If both
countanduntilentries are missing fromrrule_params, only a singleOccurrenceinstance will be created using the exactstart_timeandend_timevalues.
-
upcoming_occurrences()¶ Return all occurrences that are set to start on or after the current time.
-
next_occurrence()¶ Return the single occurrence set to start on or after the current time if available, otherwise
None.
-
daily_occurrences([dt])¶ Convenience method wrapping
Occurrence.objects.daily_occurrences.
-
OccurrenceManager¶
-
class
models.OccurrenceManager(models.Manager)¶ -
daily_occurrences([dt, event])¶ Returns a queryset of for instances that have any overlap with a particular day.
Parameters
dt- may be either a datetime.datetime, datetime.date object, or
None. IfNone, default to the current day event- can be an
Eventinstance for further filtering
-
Occurrence¶
-
class
models.Occurrence(django.db.models.Model)¶ Represents the start end time for a specific occurrence of a master
Eventobject.-
start_time¶ models.DateTimeField
-
end_time¶ models.DateTimeField
-
event¶ models.ForeignKey - a non-editable Event object
-
notes¶ generic.GenericRelation
Note
-
get_absolute_url()¶ ‘swingtime-occurrence’, [str(self.event.id), str(self.id)])
-
__cmp__()¶ Compare two
Occurrencestart times
-
title¶ Shortcut for the occurrence’s
Event.title
-
event_type¶ Shortcut for the occurrence’s
EventType
-