Remove default 'objects' manager when appending EntityManager.

This commit is contained in:
Iwo Herka 2017-09-04 13:06:16 +02:00
parent ac6dcc80c3
commit 57252d09d0
2 changed files with 55 additions and 2 deletions

47
.gitignore vendored
View file

@ -6,3 +6,50 @@
_build
build
django_eav.egg-info/*
env/
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el

View file

@ -119,12 +119,18 @@ class Registry(object):
'''
Attach the manager to *manager_attr* specified in *config_cls*
'''
# save the old manager if the attribute name conflict with the new one
# Save the old manager if the attribute name conflict with the new one.
if hasattr(self.model_cls, self.config_cls.manager_attr):
mgr = getattr(self.model_cls, self.config_cls.manager_attr)
self.config_cls.old_mgr = mgr
# attache the new manager to the model
# Remove default 'objects' manager.
for i, manager in enumerate(self.model_cls._meta.local_managers):
if manager.name == 'objects':
del self.model_cls._meta.local_managers[i]
self.model_cls._meta._expire_cache()
# Attach the new manager to the model.
mgr = EntityManager()
mgr.contribute_to_class(self.model_cls, self.config_cls.manager_attr)