django-simple-events

Lets you bind your models to events
Download

django-simple-events Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL v3
  • Publisher Name:
  • Unai Zalakain
  • Publisher web site:
  • http://unaizalakain.info/

django-simple-events Tags


django-simple-events Description

Lets you bind your models to events django-simple-events is a Django app that lets you bind your models to events. This events have the following configuration options:- beginning- time- frecuency: single time, daily, weekly, montly, yearly- interval: times between frecuencies- repetitions- endThe event occurrences are stored in the DB when an event gets saved. If you don't specify a maximum repetitions number or the end datetime, the event occurrences are updated periodically with the update_occurrences command.InstalationAdd events to your INSTALLED_APPS:INSTALLED_APPS = ( ... 'events', ... )Set EVENTS_MAX_FUTURE_OCCURRENCES to indicate the maximum of future occurrences to recolect in the DB if an event is endlessEVENTS_MAX_FUTURE_OCCURRENCES = 50You can also set EVENTS_MAX_PAST_OCCURRENCESUsageIn the following examples we are going to relate Study objects to events.ModelsIf you want to access from Study the events, it's recommendable to add a generic relationfrom django.db import modelsfrom django.contrib.contenttypes import genericfrom events.models import Eventclass Study(models.Model): ... events = generic.GenericRelation(Event) ...APIGet the events related to a Study:study = Study.objects.get(pk=1)study.events.all()Add an event to a Study:from events.models import Eventfrom datetime import date, timestudy = Study.objects.get(pk=1)event = Event(date.today(), time.now())event.related_object = studyevent.save()study.events.get(pk=event.pk)Play with the occurrences of an event:from events.models import Eventevent = Event.objects.get(pk=1)#get all the occurrences as an iter of datetimesevent.get_occurrences()#get all of past occurrences as a list of datetimesevent.get_past_occurrences()#get the last 20 past occurrences as a list of datetimesevent.get_past_occurrences(20)#get the next 20 future occurrences as a list of datetimesevent.get_future_occurrences(20)#update the Occurrence objects of an eventevent.update_occurrences(event.get_occurrences)#get the Occurrence objects of an eventevent.occurrence_set.all()#get all the Study objects that have occurrences in the futurefrom datetime import datetimeStudy.objects.filter(events__occurrence__datetime__gt=datetime.now())AdminIf, when you are editing a Study in admin, you want to also edit the related events, you are easilly done:from django.contrib import adminfrom events.admin import EventInlineclass StudyAdmin(admin.ModelAdmin): ... inlines = EventInline, ...admin.site.register(Study, StudyAdmin)FormsYou can also use the event form:from events.forms import EventForm Requirements: · Python · Django


django-simple-events Related Software