Ejemplo n.º 1
0
def user_model_swapped(**kwargs):
    if kwargs['setting'] == 'AUTH_USER_MODEL':
        from django.db.models.manager import ensure_default_manager
        # Reset User manager
        setattr(User, 'objects', User._default_manager)
        ensure_default_manager(User)
        apps.clear_cache()
Ejemplo n.º 2
0
def user_model_swapped(**kwargs):
    if kwargs['setting'] == 'AUTH_USER_MODEL':
        from django.db.models.manager import ensure_default_manager
        # Reset User manager
        setattr(User, 'objects', User._default_manager)
        ensure_default_manager(User)
        apps.clear_cache()
Ejemplo n.º 3
0
    def _prepare(cls):
        """
        Creates some methods once self._meta has been populated.
        """
        opts = cls._meta
        opts._prepare(cls)

        # Give the class a docstring -- its definition.
        if cls.__doc__ is None:
            cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join(
                f.name for f in opts.fields))

        get_absolute_url_override = settings.ABSOLUTE_URL_OVERRIDES.get(
            opts.label_lower)
        if get_absolute_url_override:
            setattr(cls, 'get_absolute_url', get_absolute_url_override)

        ensure_default_manager(cls)
        signals.class_prepared.send(sender=cls)
Ejemplo n.º 4
0
    def _on_class_prepared(self, signal, sender, **kwargs):
        model = sender
        meta = model._meta

        if not meta.abstract:
            hash_field = models.CharField(max_length=self.hash_length,
                                          unique=self._hash_unique)
            hash_field.contribute_to_class(model, self._hash_field_name)

        ensure_default_manager(model)

        for _, name, manager in (meta.abstract_managers
                                 + meta.concrete_managers):
            setattr(manager, 'get_by_hash', functools.partial(
                self._get_by_hash, manager))
            setattr(manager, 'filter_by_hash', functools.partial(
                self._filter_by_hash, manager))
            setattr(manager, 'exists_by_hash', functools.partial(
                self._exists_by_hash, manager))