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},
        # ...
    },
}

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.5.tar.gz (8.2 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.5-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_essentials_kit-0.1.5.tar.gz
  • Upload date:
  • Size: 8.2 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.5.tar.gz
Algorithm Hash digest
SHA256 4cbf6eeef5d6bd1829e6e2f93bf1a0cc79a1ac1c207769264aaa6f747abb93d5
MD5 5d7e8595e6e733ff4085554dd6efc693
BLAKE2b-256 9b6b20af34d4cbeae70896bcd4f53fcf0403cefbc373a540a56fb59bb1b14f0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_essentials_kit-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 43e6ce4d7dadad0fc824653006efa2ef5c6dfdbf3b374302b34bde3deed17e39
MD5 863d1038addad7b9f891c9b3650da8ab
BLAKE2b-256 67f7680b5b91a63c42b0fa8aa900b972f723b468e1d37d1f07aa1730e9163c48

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