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 an EventType, and associated Occurrence instances. Occurrence creation rules match those for Event.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 an EventType 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 plus swingtime_settings.DEFAULT_OCCURRENCE_DURATION hour if None

note

if not None, add a Note instance to the new event

rrule_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

class models.Note(django.db.models.Model)

A generic model for adding simple, arbitrary notes to other models such as Event or Occurrence.

note

models.TextField

created

models.DateTimeField

EventType

class models.EventType(django.db.models.Model)

Simple Event classifcation.

abbr

models.CharField

label

models.CharField

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 a freq, one will be defaulted to rrule.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 and until entries are missing from rrule_params, only a single Occurrence instance will be created using the exact start_time and end_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. If None, default to the current day

event

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