Usage🔗
This library is meant for situations where you need to do some special handling whenever data is returned though the Django ORM. Some possible use cases might be:
- Audit logging
- Obfuscation
- Checking permissions
- Validating
- Enhancing
You might have been considering Django's pre_init or post_init signals,
but realized that they do not work when using .values()
or .values_list()
.
Signals can also be hard to maintain and can be overridden on accident.
This isn't to say that using the post-fetch hooks offered by this library are strictly better. For instance, it does not fire on queryset.iterator() due to implementation details, so it that's a requirement, signals might be a better alternative.
If you're interested, here is what you would implement the hooks on your models:
You can also use the included mixins (PostFetchQuerySetMixin
and PostFetchModelMixin
)
to build the functionality in your custom models.
When using custom models, remember to set
base_manager_name = "objects"
(given that "objects" points to the manager with the post fetch functionality) in the model Meta-class so that post fetch hooks are fired on related entities.