Metadata-Version: 2.4
Name: django-unfold-settings
Version: 1.0.0
Summary: A Django package for managing typed settings via Unfold admin with strict validation and cached JSON API output.
Project-URL: Repository, https://github.com/led788/django-unfold-settings
Author-email: Denis Zaikin <led7889@gmail.com>
License: MIT
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.10
Requires-Dist: django-unfold>=0.20.0
Requires-Dist: django>=4.2
Description-Content-Type: text/markdown

# Django Unfold Settings

[![GitHub](https://img.shields.io/badge/github-led788%2Fdjango--unfold--settings-blue?logo=github)](https://github.com/led788/django-unfold-settings)

A reusable Django package for managing global application settings with multiple data types via the modern `django-unfold` admin interface. Features strict validation, automated cache management, and a high-performance flat JSON API.

## Features

- **Strict Type Validation:** EAV-inspired architecture with dedicated tables for each data type (`string`, `text`, `html`, `bool`, `json`, `date`, `datetime`, `file`).
- **Unfold Admin Integration:** Responsive UI using Unfold `TabularInline` components.
- **High Performance:** Optimized querying fetches all configs in exactly **1 SQL query**.
- **Automated Caching:** Built-in cache layer with dynamic TTL and instant invalidation via signals.

## Requirements

- Python >= 3.10
- Django >= 4.2
- django-unfold >= 0.20.0

## Installation

1. Install the package:
```bash
pip install django-unfold-settings
```

2. Add `unfold` and `unfold_settings` to `INSTALLED_APPS` in `settings.py`:
```python
INSTALLED_APPS = [
    "unfold",
    "unfold_settings",
    # ...
]
```

3. Run migrations:
```bash
python manage.py migrate
```

4. Include the API routing in your core `urls.py`:
```python
from django.urls import path, include

urlpatterns = [
    path("api/settings/", include("unfold_settings.urls")),
]
```

## Cache Configuration

You can control the API cache lifetime in `settings.py`:
```python
# Cache timeout in seconds (Default: 3600 / 1 hour)
APP_SETTINGS_CACHE_TTL = 7200  

# Disable caching completely
APP_SETTINGS_CACHE_TTL = 0  
```

## API Output

The endpoint `/api/settings/settings/` returns a flat JSON dictionary:
```json
{
  "SITE_NAME": "My App",
  "MAINTENANCE_MODE": false,
  "CONFIG": {"api_key": "12345"},
  "PROJECT_LOGO": "/media/uploads/settings/LOGO/logo.png"
}
```

## License

MIT
