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
Release history Release notifications | RSS feed
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.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_serial_preferences-0.1.0.tar.gz.
File metadata
- Download URL: django_serial_preferences-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bb42a085c370bacb33b523746ced6ff16fe41d7ea0f30e33128c370500bd77d
|
|
| MD5 |
3c26596e08eb7cf6195e0047859ba4a7
|
|
| BLAKE2b-256 |
581eebc34d12167908eac0d1e4e8a6cb17b70457b6e0f6fc389bfb50e5569962
|
Provenance
The following attestation bundles were made for django_serial_preferences-0.1.0.tar.gz:
Publisher:
publish.yml on gaurish/django-serial-preferences
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_serial_preferences-0.1.0.tar.gz -
Subject digest:
4bb42a085c370bacb33b523746ced6ff16fe41d7ea0f30e33128c370500bd77d - Sigstore transparency entry: 977480490
- Sigstore integration time:
-
Permalink:
gaurish/django-serial-preferences@830bbaf6e046af68ffa6b5de64fc5a230d6694cb -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gaurish
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@830bbaf6e046af68ffa6b5de64fc5a230d6694cb -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_serial_preferences-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_serial_preferences-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f36b7af9f50f901fbaf56996ccf710e5f5321e3ec3056e554b91445a2511752
|
|
| MD5 |
efd70be2b94bd393c78e607e594c6229
|
|
| BLAKE2b-256 |
12f970095d40bc7609e5fe2d4787eb66127908fa12eb89a115dfbc6f5ddc632e
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_serial_preferences-0.1.0-py3-none-any.whl -
Subject digest:
6f36b7af9f50f901fbaf56996ccf710e5f5321e3ec3056e554b91445a2511752 - Sigstore transparency entry: 977480521
- Sigstore integration time:
-
Permalink:
gaurish/django-serial-preferences@830bbaf6e046af68ffa6b5de64fc5a230d6694cb -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gaurish
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@830bbaf6e046af68ffa6b5de64fc5a230d6694cb -
Trigger Event:
release
-
Statement type: