A Django app for common configuration, utilities, and base models.
Project description
django-nublado-core
Common abstract models, utilities, and a simple dictionary-based app settings system for Django projects.
Overview
I found myself copying and pasting the same "core" app containing common abstract models, utilities, and app settings configuration in my Django projects, so I decided to publish it as a reusable package.
The goal is to provide simple, reliable core building blocks without introducing unnecessary complexity. The package evolves incrementally as needs arise in my projects, and is shared for others who may find it useful.
What’s included
- Abstract base models for common Django patterns (timestamps, UUIDs, published status, language).
- A small utility for typed, dictionary-based application settings using dataclasses.
Installation
Install the package from PyPI.
pip install django-nublado-core
Add the app to your Django project.
INSTALLED_APPS = [
...
"django_nublado_core",
]
The package provides only abstract models and utilities, and does not create database tables or migrations on its own.
Abstract models
These core abstract models provide common fields and related functionality used across multiple models. All models are abstract and do not create database tables or migrations on their own.
ValidatedSaveModel
An abstract model that provides an explicit helper to validate a subclassed object before saving it, without overriding the model's save method and inadvertently messing something up.
This is especially useful in cases where you want to ensure model validation is applied outside of Django forms.
Minimal example
from django.db import models
from django_nublado_core.models import ValidatedSaveModel
class Article(ValidatedSaveModel):
title = models.CharField(max_length=200)
# Sample usage
article = Article(title="hello there")
# full_clean and save
article.validate_and_save()
Notes
- Calls
full_clean()before saving. - Does not override Django’s
save()method. - Validation occurs only when
validate_and_save()is called explicitly. - Useful for explicit validation outside of forms when saving.
TimestampModel
An abstract model that adds automatic timestamp fields for object creation and updates.
Minimal example
from django.db import models
from django_nublado_core.models import TimestampModel
class Article(TimestampModel):
title = models.CharField(max_length=200)
# Sample usage
article = Article(title="hello there")
article.save()
article.date_created
article.date_updated # date_updated is refreshed on each save
Notes
- Uses timezone-aware datetimes.
Fields:
date_createddate_updated
UUIDModel
An abstract model that generates a UUID for a subclassed model's id (primary key) field.
Minimal example
from django.db import models
from django_nublado_core.models import UUIDModel
class User(UUIDModel):
username = models.CharField(max_length=200)
# Sample usage
user = User(username="Paco")
user.save()
# Primary key is a generated UUID.
user.pk # UUID('eeb4a289-034c-4e4c-9c54-98100cca1ee7')
Notes
- The generated UUID field is set as the primary key.
LanguageModel
An abstract model that provides a language choices field populated by the project's language settings.
Minimal example
LanguageModel contains an inner LanguageChoices enum derived from settings.LANGUAGES.
from django.db import models
from django_nublado_core.models import LanguageModel
class Article(LanguageModel):
title = models.CharField(max_length=200)
# Sample usage
article = Article(title="hello there")
article.save()
article.language # "en"
article.LanguageChoices.EN.value # "en"
Notes
- The default language value is taken from
settings.LANGUAGE_CODE. - Language values are validated via
full_clean(), but are not enforced at the database level by default. This is intentional. Database-level constraints can be added in concrete subclasses if needed.
PublishedModel
An abstract model for "publishable" models (e.g., blog posts, news articles) to distinguish published and draft objects.
Minimal example
PublishedModel contains an inner PublishedStatus enum with available published_status options.
from django.db import models
from django_nublado_core.models import PublishedModel
class Article(PublishedModel):
title = models.CharField(max_length=200)
# Sample usage
article = Article(title="hello there")
article.save()
article.published_status # "DRAFT"
# Article is validated and saved with published_status = "PUBLISHED", and date_published = timezone.now()
article.publish()
article.is_published # True
article.date_published # Datetime article was published.
# Article is validated and saved with published_status = "DRAFT", and date_published = None
article.unpublish()
article.is_published # False
article.date_published # None
# The PublishedStatus enum can be accessed from an object instance or the class itself.
article.PublishedStatus.PUBLISHED.value
Article.PublishedStatus.PUBLISHED.value
Notes
- The
publish()andunpublish()methods update the object'spublished_statusanddate_publishedattributes, then callfull_clean()andsave(). is_publishedis a convenience property derived frompublished_status.
Application settings
This package provides a small utility for loading typed, dictionary-based application settings using Django settings and Python dataclasses.
To configure settings for an app, define three things in a module
(conf.py or app_settings.py for example):
- The name of the settings dictionary
- A dictionary of default values
- A dataclass defining the exposed settings
Defining app settings
from dataclasses import dataclass
from django_nublado_core.conf.base import AppSettings
# The app's settings dict name (defined in Django settings.py)
SETTINGS_DICT_NAME = "YOUR_APP_SETTINGS"
# Default values for all exposed settings
SETTINGS_DEFAULTS = {
"SETTING_A": "setting A",
}
@dataclass(frozen=True)
class AppData:
SETTING_A: str
app_settings = AppSettings(
settings_dict_name=SETTINGS_DICT_NAME,
defaults=SETTINGS_DEFAULTS,
cls=AppData,
)
Overriding settings
In your project's settings.py, define a dictionary matching the configured settings name.
YOUR_APP_SETTINGS = {
"SETTING_A": "custom value",
}
Only keys explicitly declared on the dataclass are loaded. Unknown keys are ignored and logged as warnings.
Usage
The resulting app_settings object provides typed, read-only access
to your application settings.
from .config import app_settings
value = app_settings.SETTING_A
Notes
- All settings must have defaults defined.
- Settings are loaded and cached at runtime.
- Unknown user-defined keys are ignored and logged.
- The resulting settings object is immutable.
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.
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_nublado_core-0.3.0.tar.gz.
File metadata
- Download URL: django_nublado_core-0.3.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12dbf61a1cef97dfc18de107253bfaf4f458513dd138fb2a040c9031568d1b6e
|
|
| MD5 |
28f311052e6c44b173393ce75de627bd
|
|
| BLAKE2b-256 |
8be6d2d37fcb78b0c0b5be70b22f5c5da59a7900cf52625e0c85bda43347bcdb
|
File details
Details for the file django_nublado_core-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_nublado_core-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
874c4d1c75fb31ef9fc4311c28d1f6f40caf9690f3f82b749db43dd44d24abb0
|
|
| MD5 |
ed14b71eb8497ccadeb41eaa0ff8bcc9
|
|
| BLAKE2b-256 |
8a1c9d5e895b20987297dad1970c54f3318947ae0a9aec9abf55522e6d50bdc7
|