About Errors at Read-only Methods in Administration
In Django administration, read-only fields may list methods or properties of the model or model admin. However, if an AttributeError
, ValueError
, or ObjectDoesNotExist
exceptions are raised, the field will just show "-" as the value. Thats not practical for debugging. But you can re-raise the error with a custom decorator:
Put this decorator into myproject/apps/core/admin.py
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Then use it for display methods in the admin.py
files:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Tips and Tricks Programming Development Django 4.2 Django 3.2
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.