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 associatedOccurrence
instances.Occurrence
creation rules match those forEvent.add_occurrences()
.Returns the newly created
Event
instance.Parameters
event_type
can be either an
EventType
object or 2-tuple of(abbreviation,label)
, from which anEventType
is 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_time
plusswingtime_settings.DEFAULT_OCCURRENCE_DURATION
hour ifNone
note
if not
None
, add aNote
instance to the new eventrrule_params
follows the
dateutils
API (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
Occurrence
entries.- 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_params
does not contain afreq
, one will be defaulted torrule.DAILY
.Because
rrule.rrule
returns 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
count
anduntil
entries are missing fromrrule_params
, only a singleOccurrence
instance will be created using the exactstart_time
andend_time
values.
- 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 dayevent
can be an
Event
instance for further filtering
Occurrence
- class models.Occurrence(django.db.models.Model)
Represents the start end time for a specific occurrence of a master
Event
object.- 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
Occurrence
start times
- title
Shortcut for the occurrence’s
Event.title
- event_type
Shortcut for the occurrence’s
EventType