Pidalu Tech - Resusable core models, serializers and middlewares
Project description
pidalu-core
Reusable Django core utilities and base components for Django and Django REST Framework projects.
Includes model mixins, serializer tools, queryset managers, admin helpers, and middleware.
Designed to work out of the box withsettings.pyoverrides.
🚀 Features
✅ Models & Mixins
TimeStampedModel– autocreated_at,updated_atUserTrackerModel– autocreated_by,updated_byTrackedModel– combo of the aboveSlugFieldModel– auto slug from any source fieldUUIDPrimaryKeyModel– use UUIDs as primary keysSoftDeleteModel– soft deletion with manager/queryset supportAuditModel– tracks and logs field-level changesGenericRelationModel– abstract base model forGenericForeignKeysupport
🔁 QuerySet & Manager Extensions
SoftDeleteManager–.only_deleted(),.with_deleted(),.active()SoftDeleteQuerySet– compatible with manager above
📦 Serializers
DynamicFieldsModelSerializer– limit output viafields=[...]DynamicFieldsSerializer– same for plain serializersDummySerializer– no-op placeholder- (All located in
pidalu_core.serializers)
🛠 Admin Helpers
ReadOnlyAdminFieldsMixin– make selected fields readonlyAutoSlugAdminMixin– auto-prepopulateslugin admin from any field
🧠 Middleware
RequestMiddleware– stores current request in thread-localUsed to track
created_by/updated_byautomatically in models
⚙️ Installation
pip install pidalu-core
Or using Poetry:
poetry add pidalu-core
🧩 Setup
1. Add Middleware
# settings.py
MIDDLEWARE = [
"pidalu_core.middleware.RequestMiddleware", # ✅ Add near top
...
]
2. Optional Settings
# settings.py
PIDALU_CORE_AUTO_SLUG_FIELD = "name" # default source field for slug generation
🧱 Usage Examples
TrackedModel (timestamps + user)
from pidalu_core.models import TrackedModel
class Post(TrackedModel):
title = models.CharField(max_length=100)
SlugFieldModel with custom source
class Article(SlugFieldModel):
title = models.CharField(max_length=255)
slug_source_field = "title"
SoftDeleteModel with manager
class Project(SoftDeleteModel):
name = models.CharField(max_length=255)
# Usage:
Project.objects.all() # active only
Project.objects.only_deleted()
Project.objects.with_deleted()
GenericRelationModel (generic foreign key)
from pidalu_core.models import GenericRelationModel
class Tag(GenericRelationModel):
label = models.CharField(max_length=50)
# Usage:
# Tag can be attached to any model instance via `content_type` and `object_id`
DynamicFieldsModelSerializer
class UserSerializer(DynamicFieldsModelSerializer):
class Meta:
model = User
fields = ["id", "username", "email"]
# usage: UserSerializer(user, fields=["id", "email"])
request object is a cached property in Dynamic serializers, you can access request object directly without going through context.
class UserSerializer(DynamicFieldsModelSerializer):
class Meta:
model = User
fields = ["id", "username", "email"]
def get_fields(self):
fields = super().get_fields()
if self.request.method.lower() == 'get': # directly access request object
fields["details"] = UserDetailSerializer(fields=["address", "bio"])
return fields
🧪 Testing
Use Makefile > test.
Setup
make test
Or directly with Poetry, uses pytest and pytest-django under the hood:
PYTHONPATH=. poetry run pytest -vv
We use in-memory SQLite + dynamic schema creation.
👤 Author
Built and maintained by Pidalu Tech Team.
🪪 License
MIT License — free to use, modify, and distribute.
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 pidalu_core-0.1.3.tar.gz.
File metadata
- Download URL: pidalu_core-0.1.3.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3edde4ea1da3f66483a7e3263297cbdf7351f1c2f189220aaf21e0be86bcf3ca
|
|
| MD5 |
d4a63da9d4208f480a1842aff584807e
|
|
| BLAKE2b-256 |
851806884bb47b91d74a7543d0d24b50887b854e835d11a49290dd5853ffe318
|
File details
Details for the file pidalu_core-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pidalu_core-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6faedf86b4e5360ca70bc630dd90a85e460f81209dd2449c00f5c51c914ead53
|
|
| MD5 |
95f90f20c1bcaee6bf932b6d53901ed0
|
|
| BLAKE2b-256 |
5f1eed93e6cc0731e18b65c849fb2801deac42da15e10793d9e1861aa0e4aee8
|