Skip to main content

Create repeating datetimes in django using dateutil rrulesets

Project description

https://img.shields.io/pypi/v/django_recurring.svg https://img.shields.io/travis/boosh/django_recurring.svg Documentation Status

Create repeating datetimes in Django using dateutil rrulesets with timezone awareness.

Features

  • Create complex recurring date patterns using dateutil rrulesets

  • Automatically calculate previous and next occurrences for efficient date range queries

  • Timezone-aware datetime handling

  • Export recurrence sets to iCal format

  • Admin interface with custom widget for creating and editing recurrence patterns

Limitations

This library currently has the following limitations.

  • All date ranges require an end date.

    The count param isn’t supported.

PRs welcome.

Quick Start

  1. Install django-recurring:

    pip install django-recurring
  2. Add ‘recurring’ to your INSTALLED_APPS:

    INSTALLED_APPS = [
        ...
        'recurring',
    ]
  3. Run migrations:

    python manage.py migrate recurring
  4. Add a RecurrenceSet to your model:

    from django.db import models
    from recurring.models import RecurrenceSet
    
    class Event(models.Model):
        name = models.CharField(max_length=200)
        recurrence = models.ForeignKey(RecurrenceSet, on_delete=models.CASCADE)
  5. Use the RecurrenceSet in your code:

    from django.utils import timezone
    from recurring.models import RecurrenceSet, RecurrenceRule, RecurrenceSetRule
    
    # Create a RecurrenceSet
    recurrence_set = RecurrenceSet.objects.create(name="Weekly Meeting")
    
    # Create a RecurrenceRule
    rule = RecurrenceRule.objects.create(
        frequency=RecurrenceRule.Frequency.WEEKLY,
        interval=1,
        byweekday=[0]  # Monday
    )
    
    # Add a date range to the rule
    rule.date_ranges.create(
        start_date=timezone.now(),
        end_date=timezone.now() + timezone.timedelta(days=365)
    )
    
    # Link the rule to the RecurrenceSet
    RecurrenceSetRule.objects.create(
        recurrence_set=recurrence_set,
        recurrence_rule=rule
    )
    
    # Recalculate occurrences
    recurrence_set.recalculate_occurrences()
    
    # Query events within a date range
    events = Event.objects.filter(
        recurrence__next_occurrence__gte=timezone.now(),
        recurrence__previous_occurrence__lte=timezone.now() + timezone.timedelta(days=30)
    )
  6. Export to iCal format:

    ical_string = recurrence_set.to_ical()
    with open('weekly_meeting.ics', 'w') as f:
        f.write(ical_string)

For more detailed usage and examples, see the documentation.

Why?

django-recurrence lacks multiple features (e.g. times, hourly intervals, etc) that don’t seem possible to solve. A new library was in order.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_recurring-0.2.0.tar.gz (561.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_recurring-0.2.0-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

Details for the file django_recurring-0.2.0.tar.gz.

File metadata

  • Download URL: django_recurring-0.2.0.tar.gz
  • Upload date:
  • Size: 561.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for django_recurring-0.2.0.tar.gz
Algorithm Hash digest
SHA256 90983a701a251146d5f80340ddacbfed65dc0714370b7bf8a6efa4d19cb90cfa
MD5 37807c6ad62474defc36f3985b74a9b1
BLAKE2b-256 66ae66f32eaa0909b93e1af93e29a4fd0c38f215bf290ac754ce5a885083af21

See more details on using hashes here.

File details

Details for the file django_recurring-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_recurring-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed63ed6cfbf43c3a069e5f321eaa926da3bfbaf2ff9b1946745ca4ffaad9d156
MD5 0cafcfdd2e13eb4092699f31c6827fb1
BLAKE2b-256 24d0aa3aef92273e511e9cb2ccced4c2879ac239341a9a1529c152b2778e1c36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page