Skip to main content

Essential utilities for Django

Project description

Django Essentials

Essential utilities for Django that make common tasks easier and more efficient.

Features

  • Admin Utilities: Enhanced admin interface components including FancyBox image display
  • Model Utilities: Helper functions for common model operations

Installation

pip install django-essentials-kit

Quick Start

Admin Utilities

The library provides MediaFancybox class and get_fancybox_image function for enhanced image display in Django admin:

from django.contrib import admin
from django_essentials_kit.admin import MediaFancybox, get_fancybox_image
from .models import YourModel

@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
    list_display = ['name', 'image_preview']

    class Media(MediaFancybox):
        ...

    def image_preview(self, obj) -> SafeString:
        return get_fancybox_image(obj, 'image_field', w=60, h=60)

Model Utilities

Use get_object_or_none for safe object retrieval:

from django_essentials_kit.utils import get_object_or_none

from .models import YourModel

# Instead of try/except blocks
obj = get_object_or_none(YourModel, pk=1)
if obj:
    ...  # Do something with obj

JSON Logger Formatter

Add to settings.py:

LOGGING = {
    "version": 1,
    "disable_existing_loggers": True,
    "root": {"level": "INFO", "handlers": ["console"]},
    "formatters": {
        "json": {
            "format": "[%(levelname)s][%(asctime)s] %(module)s.%(funcName)s:%(lineno)d: %(message)s",
            "()": "django_essentials_kit.logger_formatter.JSONFormatter",
        },
    },
    "handlers": {
        "console": {"level": "INFO", "class": "logging.StreamHandler", "formatter": "json"},
    },
    "loggers": {
        "django": {"level": "DEBUG", "handlers": ["console"], "propagate": False},
        # ...
    },
}

Logging HTTP request-response

Add to settings.py:

MIDDLEWARE = [
    "django_essentials_kit.middlewares.DjangoLoggingMiddleware",
    # ...
]

It will be added to the logs:

  • real_client_ip if it is routable
  • is_succeeded (200 <= status < 300 - true else false)
  • request details:
    • status_code
    • method
    • path
  • user_id if a user is signed in
  • real_client_ip (if routable)

Requirements

  • Python 3.8+
  • Django 3.2+

License

MIT License - see LICENSE file for details.

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

django_essentials_kit-0.1.6.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

django_essentials_kit-0.1.6-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file django_essentials_kit-0.1.6.tar.gz.

File metadata

  • Download URL: django_essentials_kit-0.1.6.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for django_essentials_kit-0.1.6.tar.gz
Algorithm Hash digest
SHA256 35d0721dbc59098e2fddf8476b9f2ab6bc1a3093630be431e9d33fd9f31b0e51
MD5 93cc343d6789fe752b2053130caf46e8
BLAKE2b-256 4995e35743178b7371ecb81c4f2bc49cf574d22dfc012b06cbd46a3f5cd41690

See more details on using hashes here.

File details

Details for the file django_essentials_kit-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_essentials_kit-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8c0b09c8a3264a649dc9643f7441348a03dfe27e76da153aacb22d86860db329
MD5 4a135ce7bc8b73c5343f8097c981b564
BLAKE2b-256 fe8fbf5d11f851d0f8a18699a0b918dbef74c55d8dc7428981a18feb04942045

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