Skip to main content

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 with settings.py overrides.


🚀 Features

✅ Models & Mixins

  • TimeStampedModel – auto created_at, updated_at
  • UserTrackerModel – auto created_by, updated_by
  • TrackedModel – combo of the above
  • SlugFieldModel – auto slug from any source field
  • UUIDPrimaryKeyModel – use UUIDs as primary keys
  • SoftDeleteModel – soft deletion with manager/queryset support
  • AuditModel – tracks and logs field-level changes
  • GenericRelationModel – abstract base model for GenericForeignKey support

🔁 QuerySet & Manager Extensions

  • SoftDeleteManager.only_deleted(), .with_deleted(), .active()
  • SoftDeleteQuerySet – compatible with manager above

📦 Serializers

  • DynamicFieldsModelSerializer – limit output via fields=[...]
  • DynamicFieldsSerializer – same for plain serializers
  • DummySerializer – no-op placeholder
  • (All located in pidalu_core.serializers)

🛠 Admin Helpers

  • ReadOnlyAdminFieldsMixin – make selected fields readonly
  • AutoSlugAdminMixin – auto-prepopulate slug in admin from any field

🧠 Middleware

  • RequestMiddleware – stores current request in thread-local

    Used to track created_by/updated_by automatically 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

pidalu_core-0.1.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pidalu_core-0.1.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

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

Hashes for pidalu_core-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3edde4ea1da3f66483a7e3263297cbdf7351f1c2f189220aaf21e0be86bcf3ca
MD5 d4a63da9d4208f480a1842aff584807e
BLAKE2b-256 851806884bb47b91d74a7543d0d24b50887b854e835d11a49290dd5853ffe318

See more details on using hashes here.

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

Hashes for pidalu_core-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6faedf86b4e5360ca70bc630dd90a85e460f81209dd2449c00f5c51c914ead53
MD5 95f90f20c1bcaee6bf932b6d53901ed0
BLAKE2b-256 5f1eed93e6cc0731e18b65c849fb2801deac42da15e10793d9e1861aa0e4aee8

See more details on using hashes here.

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