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

If you need any help then please contact with use.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: djangotoolspack-0.0.2.tar.gz
  • Upload date:
  • Size: 6.4 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.2.tar.gz
Algorithm Hash digest
SHA256 882d06ecff312ecba421e3cfbb7a21475504c650abe06285f4a5da2279cfe694
MD5 e52149c7443e70154658c20dc9d158fa
BLAKE2b-256 c177ab65fd76aec0ca80cb1f2bcb0d67a12164db85ec9e2ac4c262d7f968d07c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for djangotoolspack-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e3b4bcec6ab3656b216763b7b3926d35d38491b023f33f6b636a53dbbe6e0c9
MD5 f16c55cfdd16ca4674c215d29b0a6245
BLAKE2b-256 d10a1c9670e9ff992a459dc75201ee46bd0082d3622fdc9ac705cf92946fd7d5

See more details on using hashes here.

Provenance

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