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.

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.1.0.tar.gz (304.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.1.0-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_recurring-0.1.0.tar.gz
  • Upload date:
  • Size: 304.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.1.0.tar.gz
Algorithm Hash digest
SHA256 9d9b1be5089d053397f9c67312418762241cdfe4dc1463234a72d81338ef410e
MD5 2928628bba9d21de85f76d8152d847f6
BLAKE2b-256 813ddcf2aeac8902a3047cfb38cbe8619d784997ee668834ad2b8616d740ba08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_recurring-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18a2b1d1e98a3ab9e9581393c59f75e613f8415e1fa8ee916d0a75ae72c856f0
MD5 abb8b424b74518e4dbe47edfd1b8adf9
BLAKE2b-256 2b9804579e04f1106649539761b7f0edffa2c2ebde56607b7eab4be614a25dcd

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