Skip to main content

Reusable Django and DRF helpers for pagination, model auditing, admin tracking, and serializers

Project description

Django Tools Pack Usage Guide

This guide is for application developers who want to install the package and use it directly in their Django project.

1) Install

pip install djangotoolspack

2) Add to INSTALLED_APPS

In your Django settings:

INSTALLED_APPS = [
    # your apps...
    "djangotoolspack",
]

3) Import what you need

from djangotoolspack import (
    TimestampedMixin,
    UserTrackedMixin,
    AuditLogMixin,
    AdminMixin,
    SerializerMixin,
    StandardPaginationResult,
)

4) Use mixins in models

from django.db import models
from djangotoolspack import AuditLogMixin


class Product(AuditLogMixin, models.Model):
    name = models.CharField(max_length=120)
    price = models.DecimalField(max_digits=10, decimal_places=2)

What you get automatically:

  • created_at
  • updated_at
  • created_by
  • updated_by

5) Use AdminMixin in Django admin

from django.contrib import admin
from djangotoolspack import AdminMixin
from .models import Product


@admin.register(Product)
class ProductAdmin(AdminMixin):
    list_display = ("id", "name", "created_at", "updated_at")

AdminMixin sets:

  • created_by when object is first created in admin
  • updated_by on every admin save

6) Use SerializerMixin for file URLs and field ordering

from rest_framework import serializers
from djangotoolspack import SerializerMixin
from .models import Product


class ProductSerializer(SerializerMixin, serializers.ModelSerializer):
    class Meta:
        model = Product
        fields = ["id", "name", "image", "price"]

        # Converts file fields to URL (or None)
        file_fields = ["image"]

        # Moves listed fields to the end in this exact order
        fields_ordering = ["price", "id"]

7) Use StandardPaginationResult in API views

from rest_framework.views import APIView
from djangotoolspack import StandardPaginationResult
from .models import Product
from .serializers import ProductSerializer


class ProductListApi(APIView):
    def get(self, request):
        queryset = Product.objects.all().order_by("-id")

        paginator = StandardPaginationResult()
        page_items = paginator.paginate_queryset(queryset, request, view=self)
        serializer = ProductSerializer(page_items, many=True)

        return paginator.get_paginated_response(
            serializer.data,
            message="Products fetched successfully",
            status_code=200,
        )

Supported query params:

  • page
  • page_size

Typical import pattern

Import directly from the package root:

from djangotoolspack import AuditLogMixin, StandardPaginationResult

Troubleshooting VS Code import warnings

If VS Code shows Import "djangotoolspack" could not be resolved, the package is usually installed in a different Python environment than the one selected in VS Code.

Fix it by making sure the consuming project uses the same interpreter where the package was installed:

python -m pip install djangotoolspack

For local development from a checkout, use an editable install instead:

python -m pip install -e /path/to/djangotoolspack

If the import still looks unresolved in VS Code, reload the window or select the correct interpreter from Python: Select Interpreter.

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

djangotoolspack-0.0.3.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

djangotoolspack-0.0.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file djangotoolspack-0.0.3.tar.gz.

File metadata

  • Download URL: djangotoolspack-0.0.3.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for djangotoolspack-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1f82d1f85c2f4c8fdac06bfa4b9e4bf0ddcc89d3c7d2c50f5ff2f922142c5c90
MD5 2f223d9aa8288b9ddeb63d8659269656
BLAKE2b-256 9368bde62296ceb0daa50240b93bf25ef6199b11f3eb8fe76d72b27db421423d

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangotoolspack-0.0.3.tar.gz:

Publisher: python-publish.yml on chinmayroy/djangotoolspack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djangotoolspack-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for djangotoolspack-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ea47a59e1cffbf2e4dee473d279ea517e712353dedf5dc404bfc03642c4b8f86
MD5 61a22fe62dc696e8b79f6be3221f295c
BLAKE2b-256 4cb4f1368f34ab6c3964e1af046e3654a4d169eebc22824d1ad0db20492217d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangotoolspack-0.0.3-py3-none-any.whl:

Publisher: python-publish.yml on chinmayroy/djangotoolspack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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