Skip to main content

Typed, grouped preferences for Django models with schema introspection

Project description

django-serial-preferences

Typed, grouped preferences for Django models with schema introspection.

Install

pip install django-serial-preferences

Quick Start

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

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

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

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_serial_preferences-0.1.0.tar.gz (12.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_serial_preferences-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_serial_preferences-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4bb42a085c370bacb33b523746ced6ff16fe41d7ea0f30e33128c370500bd77d
MD5 3c26596e08eb7cf6195e0047859ba4a7
BLAKE2b-256 581eebc34d12167908eac0d1e4e8a6cb17b70457b6e0f6fc389bfb50e5569962

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_serial_preferences-0.1.0.tar.gz:

Publisher: publish.yml on gaurish/django-serial-preferences

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for django_serial_preferences-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f36b7af9f50f901fbaf56996ccf710e5f5321e3ec3056e554b91445a2511752
MD5 efd70be2b94bd393c78e607e594c6229
BLAKE2b-256 12f970095d40bc7609e5fe2d4787eb66127908fa12eb89a115dfbc6f5ddc632e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_serial_preferences-0.1.0-py3-none-any.whl:

Publisher: publish.yml on gaurish/django-serial-preferences

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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