Skip to main content
Project generated with PyScaffold PyPI-Server GitHub Test CI Monthly Downloads

django-better-repr

Django model reprs for humans!

This project seeks to make reprs of Django models more human-friendly. This project is heavily inspired by https://github.com/dan-passaro/django-auto-repr .

Installation

pip install django-better-repr

If you want to automatically improve the repr of all models in your project then add django_better_repr to your installed apps.

# settings.py
INSTALLED_APPS = [
   ...,
   'django_better_repr',
   ...,
]

Want to customize which apps get configured but don’t want to decorate each class individually? Head on down to the Configuration section.

How to use:

The repr logic in this library is designed to produce the smallest, most meaningful repr possible for your Django models. That means that fields which aren’t set won’t show up in the repr. This should reduce noise and let you get the most value out of your reprs.

from django_better_repr import better_repr

@better_repr
class MyDjangoModel(models.Model):
    my_field = models.CharField(max_length=16)

Or, if class inheritance is more your speed:

from django_better_repr.bases import BetterRepr

class MyDjangoModel(BetterRepr, models.Model):
    my_field = models.CharField(max_length=16)

Then load up your favorite shell and run:

MyDjangoModel.objects.create(my_field='Hello, world!')
>>> MyDjangoModel(my_field='Hello, world!')

If your model has a lot of fields then the repr will automatically switch to pretty printing. This can be configured via settings.

Configuration

If you want to customize the behavior of the library, below are all the options.

# settings.py
BETTER_REPR_CONFIG = {
   'ENABLE_MULTILINE_REPRS': True,  # bool (default: True), whether or not to allow multiline reprs
   'SINGLE_LINE_PARTS_LIMIT': 4,  # int (default: 4), the number of fields a repr can have before switching to multi line
   'MULTILINE_WHITESPACE': '\t',  # str (default: '\t'), the whitespace string to use for multiline reprs
   'AUTO_CONFIGURE_INCLUDE_MODELS': [],  # list (default: a sentinel for all models), which models to auto include if the auto configuration application is added to INSTALLED_APPS
   'AUTO_CONFIGURE_EXCLUDE_MODELS': [],  # list (default: []), which models to exclude from the auto setup if the auto configuration application is added to INSTALLED_APPS
   'EXCLUDE_DEFERRED_FIELDS': True,  # bool (default: True), whether or not to exclude deferred fields (https://docs.djangoproject.com/en/4.2/ref/models/querysets/#django.db.models.query.QuerySet.defer) from the repr
}

Making Changes & Contributing

This project uses pre-commit, please make sure to install it before making any changes:

pip install pre-commit
cd django-better-repr
pre-commit install

It is a good idea to update the hooks to the latest version:

pre-commit autoupdate

Note

This project has been set up using PyScaffold 4.5. For details and usage information on PyScaffold see https://pyscaffold.org/.

Release files for django-better-repr 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-better-repr 1.0.7
File Size Uploaded
django-better-repr-1.0.7.tar.gz 30.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-better-repr 1.0.7
File Interpreter ABI Platform
django_better_repr-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 38.2 kB

Release files / django-better-repr-1.0.7.tar.gz

Download URL django-better-repr-1.0.7.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
62f6499409830b1c2730f0ec9336f325fdb0af1ebfa6799a1cf9cdd08dee60fa
BLAKE2b-256 checksum
How to use checksums
151bac83de8132206fb60d6559e44909003e70c19228c9605991b1984d44edab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / django_better_repr-1.0.7-py3-none-any.whl

Download URL django_better_repr-1.0.7-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa3699d825db48fd6793a88a4730c093d5f43e1fd859f4415980c4ec204b782c
BLAKE2b-256 checksum
How to use checksums
f4ca5d413741dd8f0b9bc845b6073a03190d855969a1c4ff50f5995a875f05b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.0.7 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page