Django model reprs for humans!
Project description
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
And that’s it!
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 }
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/.
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
Built Distribution
Hashes for django_better_repr-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d1e52e2e088ee1dd769a9b80b8bdab18bc9da84db0e66499cdfced42fe7e6d0 |
|
MD5 | c89d937284b501b303ee5e3456394187 |
|
BLAKE2b-256 | e467a22d650938facd9b3c7ed1fd28d8d4c04c74dc3f80f76bc46936410ec6a6 |