Skip to main content

Django model reprs for humans!

Project description

Project generated with PyScaffold

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 .

How to use:

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
}

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

Don’t forget to tell your contributors to also install and use pre-commit.

Note

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

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-better-repr-1.0.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

django_better_repr-1.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file django-better-repr-1.0.1.tar.gz.

File metadata

  • Download URL: django-better-repr-1.0.1.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for django-better-repr-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0853834717a2ab27a91f1529f3ff2e9b1538f34cf1456008fe7c11976109e227
MD5 9b7d26d19ed5ff942688979be2643f4e
BLAKE2b-256 7e6298018d606d9eed0a86623e60a5703f54bfc0c94f065a2d91de38cb6f1b58

See more details on using hashes here.

File details

Details for the file django_better_repr-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_better_repr-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dcd038e7d305664c14d026065c3f67f72f9d6f6f660d8a4327061c2441772ac2
MD5 ae4c88cb5b6b1f3ded0f6a8645d7dc9a
BLAKE2b-256 6f89b925e7e504ee3f7d67f8ae88d32ace092251874ac024203eec8448d158cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page