Metadata-Version: 2.4
Name: django-serial-preferences
Version: 0.1.0
Summary: Typed, grouped preferences for Django models with schema introspection
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: django>=4.2
Provides-Extra: dev
Requires-Dist: pytest-django>=4.5; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: strawberry-graphql>=0.220.0; extra == 'dev'
Provides-Extra: strawberry
Requires-Dist: strawberry-graphql>=0.220.0; extra == 'strawberry'
Description-Content-Type: text/markdown

# django-serial-preferences

Typed, grouped preferences for Django models with schema introspection.

## Install

```bash
pip install django-serial-preferences
```

## Quick Start

```python
from serial_preferences import PreferenceSchema, PreferenceGroup, Pref
from serial_preferences.django import PreferenceField

class BusinessPreferences(PreferenceSchema):
    class General(PreferenceGroup, label="General Settings"):
        store_name_on_receipt: bool = Pref(default=True, label="Show store name on receipt")
        receipt_footer: str = Pref(default="Thank you!", label="Receipt footer", max_length=200)

    class Fuel(PreferenceGroup, label="Fuel Settings"):
        prepay_enabled: bool = Pref(default=True, label="Enable fuel prepay")
        max_prepay_amount: int = Pref(default=15000, label="Max prepay (cents)", ge=0)

class Business(models.Model):
    preferences = PreferenceField(BusinessPreferences)

# Usage
biz = Business.objects.create()
biz.preferences.prepay_enabled        # True (default)
biz.preferences.max_prepay_amount = 200
biz.save()
```

## Inheritance

```python
class Location(models.Model):
    business = models.ForeignKey(Business, on_delete=models.CASCADE)
    preferences = PreferenceField(BusinessPreferences, inherits_from="business.preferences")

loc.preferences.prepay_enabled        # falls back to business value
loc.preferences.is_inherited("prepay_enabled")  # True
loc.preferences.set("prepay_enabled", False)     # local override
loc.preferences.reset("prepay_enabled")          # remove override
```

## Schema Introspection

```python
BusinessPreferences.to_schema()
# Returns list of groups with preference definitions for form generation
```
