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

🔁 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()

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.2.tar.gz (5.9 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.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file pidalu_core-0.1.2.tar.gz.

File metadata

  • Download URL: pidalu_core-0.1.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for pidalu_core-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c0517244ce97880684d665cd2bebe7310748a4b533abc4020f8631d491ed8f2a
MD5 b032dd410a229e58306883c47adc67f8
BLAKE2b-256 92a6d131819f370349ea245651be9bcfce05795733e93c40e9476ba05d6748a4

See more details on using hashes here.

File details

Details for the file pidalu_core-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pidalu_core-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for pidalu_core-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 386b47e28600b9e4d9e6c6b88833c91969fb01707ee541dcfa76c7dea6de5d6f
MD5 3b0b3e73e02806f14abd57c9432cb3da
BLAKE2b-256 b5f43b988eb424ca062fde0a4c99121a02ed26e5a78173f2f138721ccaae6ca9

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