Project description
Reusable Django app for modelling provider/resource availability with weekly hours, breaks, one-off exceptions, and optional tenant-wide holidays. It answers “when can this provider be booked?” and stays out of booking/slot generation concerns.
Features
- Weekly recurring working windows per provider
- Recurring breaks inside working windows
- Exceptions for closed days and special hours
- Optional tenant holidays (enabled when a tenant model is configured)
- Timezone-safe selectors that return aware datetimes
- Admin UX tuned for day-of-week workflows
Installation
- Add the package and Django to your project (Django 4.2+):
pip install django-availability
- Configure settings:
AVAILABILITY_PROVIDER_MODEL(required): the provider model asapp_label.ModelName(default:"providers.Provider").AVAILABILITY_TENANT_MODEL(optional): tenant model asapp_label.ModelName. When set, tenant FKs are added to models and TenantHoliday is enabled.
- Add to
INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"availability",
]
- Run migrations:
python manage.py migrate
Models
WeeklyAvailability: recurring weekly working windows (weekday, start_time, end_time, is_active, sort_order).AvailabilityBreak: recurring breaks per weekday that subtract from working windows.AvailabilityException: one-off CLOSED or SPECIAL_HOURS per date; unique per provider+date.TenantHoliday(tenant mode only): tenant-wide closed dates.
Validation rules:
end_timemust be afterstart_time.- Active weekly windows/breaks cannot overlap for a provider+weekday.
- SPECIAL_HOURS require start/end; CLOSED must not provide times.
- Tenant consistency enforced when
AVAILABILITY_TENANT_MODELis set.
Public API (selectors)
Import from availability.selectors:
get_working_windows_for_date(provider, date, tz=None) -> list[(start_dt, end_dt)]get_working_windows(provider, start_date, end_date, tz=None) -> dict[date, list[(start_dt, end_dt)]]is_provider_available(provider, dt, tz=None) -> bool
Example:
from datetime import date, datetime
from django.utils import timezone
from availability.selectors import get_working_windows_for_date, is_provider_available
provider = ...
target_date = date(2024, 1, 1)
tz = timezone.get_current_timezone()
windows = get_working_windows_for_date(provider, target_date, tz=tz)
if is_provider_available(provider, datetime(2024, 1, 1, 10, 30), tz=tz):
print("open")
The selectors:
- honor CLOSED/SPECIAL_HOURS exceptions
- subtract breaks from weekly or special-hour windows
- close days that fall on tenant holidays (if enabled)
- return timezone-aware datetimes;
tzdefaults to Django’s current timezone
Admin
Admin list filters cover weekday/kind/tenant and call full_clean() on save for safety. Ordering is optimized for weekday flows.
Testing locally
This repo ships a minimal test project. Run:
python test availability
The helper script pins DJANGO_SETTINGS_MODULE=tests.settings so the bundled test provider/tenant models are used. You can pass other labels, e.g. python test tests.
Releasing to PyPI
- Bump version: update
pyproject.toml(andavailability/__init__.pyif mirroring). - Clean dist: remove old artifacts:
rm -rf dist/ build/ *.egg-info. - Build:
python -m pip install --upgrade build twine
python -m build
- Check:
python -m twine check dist/*. - Publish (replace token):
python -m twine upload dist/* -u __token__ -p pypi-XXXXXXXXXXXXXXXXXXXX.- For TestPyPI:
python -m twine upload --repository testpypi dist/*.
- For TestPyPI:
- Verify install (optional):
pip install --no-cache-dir django-availability.
Scope notes
- No booking/slot generation/payment/notification logic.
- Datetimes are expected/stored in UTC; local rules are weekday + local times.
- Overnight windows are not supported in v0.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
File details
Details for the file django_availability-0.1.0.tar.gz.
File metadata
- Download URL: django_availability-0.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf75ca825a8de10dd8cf391e421be462911f115bb95b3b4ff54fcfdd8868c05b
|
|
| MD5 |
56978bcdb801a226c94c219f1bf275ca
|
|
| BLAKE2b-256 |
b3c37c104f85bea7332fcc7591362e29a4b96b2baad9e6c12a4a50f2d49201e1
|
File details
Details for the file django_availability-0.1.0-py3-none-any.whl.
File metadata
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bdf0a476b5a441e42fbf42859f621f4f1fab040a776c8cef6fe785a5839400d
|
|
| MD5 |
635789a79e0a8e5cc6f14ced06055b81
|
|
| BLAKE2b-256 |
db22e02da355b22413274cbcc5eaa1c23ee9022d93fede7c60212a774cc31260
|