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_atupdated_atcreated_byupdated_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_bywhen object is first created in adminupdated_byon 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:
pagepage_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f82d1f85c2f4c8fdac06bfa4b9e4bf0ddcc89d3c7d2c50f5ff2f922142c5c90
|
|
| MD5 |
2f223d9aa8288b9ddeb63d8659269656
|
|
| BLAKE2b-256 |
9368bde62296ceb0daa50240b93bf25ef6199b11f3eb8fe76d72b27db421423d
|
Provenance
The following attestation bundles were made for djangotoolspack-0.0.3.tar.gz:
Publisher:
python-publish.yml on chinmayroy/djangotoolspack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangotoolspack-0.0.3.tar.gz -
Subject digest:
1f82d1f85c2f4c8fdac06bfa4b9e4bf0ddcc89d3c7d2c50f5ff2f922142c5c90 - Sigstore transparency entry: 1437021393
- Sigstore integration time:
-
Permalink:
chinmayroy/djangotoolspack@b000e9185d474c33d11b51478537435a9ab79a64 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/chinmayroy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b000e9185d474c33d11b51478537435a9ab79a64 -
Trigger Event:
release
-
Statement type:
File details
Details for the file djangotoolspack-0.0.3-py3-none-any.whl.
File metadata
- Download URL: djangotoolspack-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea47a59e1cffbf2e4dee473d279ea517e712353dedf5dc404bfc03642c4b8f86
|
|
| MD5 |
61a22fe62dc696e8b79f6be3221f295c
|
|
| BLAKE2b-256 |
4cb4f1368f34ab6c3964e1af046e3654a4d169eebc22824d1ad0db20492217d7
|
Provenance
The following attestation bundles were made for djangotoolspack-0.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on chinmayroy/djangotoolspack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangotoolspack-0.0.3-py3-none-any.whl -
Subject digest:
ea47a59e1cffbf2e4dee473d279ea517e712353dedf5dc404bfc03642c4b8f86 - Sigstore transparency entry: 1437021416
- Sigstore integration time:
-
Permalink:
chinmayroy/djangotoolspack@b000e9185d474c33d11b51478537435a9ab79a64 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/chinmayroy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b000e9185d474c33d11b51478537435a9ab79a64 -
Trigger Event:
release
-
Statement type: