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

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.1.tar.gz (6.3 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.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djangotoolspack-0.0.1.tar.gz
  • Upload date:
  • Size: 6.3 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.1.tar.gz
Algorithm Hash digest
SHA256 fdf73d4e5f85e1193a495e5933e03590ff880effb8bb61ed07404b549f689540
MD5 711ae25f19b7771bd3e6b9b760e23a98
BLAKE2b-256 ce827bba87ec1e896b7c07bf507297f6b0225fd5f1f46cce26530c6f638988f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangotoolspack-0.0.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for djangotoolspack-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dbdc14df9572c7e5eb025037fc5e8ed88cb030ad9f855882c661fd7b95c469e5
MD5 80326b9fbeb647239a1c1d3c7812fde8
BLAKE2b-256 f2bf6d13277f2ba32c165080e344ceddaad01a44f8317fb971eb0a6dc28b1198

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangotoolspack-0.0.1-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