Hello,
> On 27 Aug 2016, at 00:57, Paulo Gabriel Poiati <[email protected]> wrote:
>
> What if we allow the change of the default manager of all models?
>
> This could be done through the settings, something like DEFAULT_MODEL_MANAGER.
If you’ve been following this mailing list for some time, you may have noticed
that proposals to add new settings aren’t very popular :-)
> Of course this can be done if all models extends a custom class (that change
> the default manager).
This is indeed the approach I would suggest. Many projects do this, typically
to add created_at, updated_at, UUID, etc
> But what about changing it between environments? Like using a mock specific
> Manager during the tests, this could be really useful IMO.
You can do this with a custom setting. It doesn’t have to be implemented in
Django. Just import dynamically your manager class:
from django.conf import settings
from django.utils.module_loading import import_string
DefaultManager = import_string(settings.DEFAULT_MODEL_MANAGER)
and apply it to your base class for your model, or anywhere else you need it:
from django.db import models
class ModelBase(models.Model):
objects = DefaultManager()
Best regards,
--
Aymeric.
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/0634F361-43D0-4996-AF1D-49C7816F5BD5%40polytechnique.org.
For more options, visit https://groups.google.com/d/optout.