mirror of
https://github.com/jazzband/django-eav2.git
synced 2026-03-16 22:40:26 +00:00
Added register / unregister to __init__
This commit is contained in:
parent
41ff6972a2
commit
ebf979fa53
3 changed files with 26 additions and 18 deletions
|
|
@ -34,4 +34,11 @@ def get_version():
|
|||
|
||||
__version__ = get_version()
|
||||
|
||||
def register(model_cls, config_cls=None):
|
||||
from registry import Registry, EavConfig
|
||||
config_cls = config_cls or EavConfig
|
||||
Registry.register(model_cls, config_cls)
|
||||
|
||||
def unregister(model_cls):
|
||||
from registry import Registry
|
||||
Registry.unregister(model_cls)
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class Registry(object):
|
|||
|
||||
|
||||
@staticmethod
|
||||
def register(model_cls, config_cls=EavConfig, manager_only=False):
|
||||
def register(model_cls, config_cls=EavConfig):
|
||||
"""
|
||||
Inject eav features into the given model and attach a signal
|
||||
listener to it for setup.
|
||||
|
|
@ -175,7 +175,7 @@ class Registry(object):
|
|||
|
||||
Registry.attach_manager(model_cls)
|
||||
|
||||
if not manager_only:
|
||||
if not config_cls.manager_only:
|
||||
Registry.attach_signals(model_cls)
|
||||
Registry.attach_generic_relation(model_cls)
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ class Registry(object):
|
|||
|
||||
Registry.detach_manager(model_cls)
|
||||
|
||||
if not manager_only:
|
||||
if not config_cls.manager_only:
|
||||
Registry.detach_signals(model_cls)
|
||||
Registry.detach_generic_relation(model_cls)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ from datetime import datetime
|
|||
from django.test import TestCase
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
import eav
|
||||
from ..models import *
|
||||
from ..registry import Registry, EavConfig
|
||||
from ..registry import EavConfig
|
||||
from .models import Patient
|
||||
|
||||
|
||||
|
|
@ -16,8 +17,8 @@ class EavSetterAndGetterTests(TestCase):
|
|||
|
||||
|
||||
def setUp(self):
|
||||
Registry.unregister(Patient)
|
||||
Registry.register(Patient)
|
||||
eav.unregister(Patient)
|
||||
eav.register(Patient)
|
||||
|
||||
self.attribute = Attribute.objects\
|
||||
.create(datatype=Attribute.TYPE_TEXT,
|
||||
|
|
@ -31,8 +32,8 @@ class EavSetterAndGetterTests(TestCase):
|
|||
|
||||
|
||||
def tearDown(self):
|
||||
Registry.unregister(Patient)
|
||||
Registry.unregister(User)
|
||||
eav.unregister(Patient)
|
||||
eav.unregister(User)
|
||||
|
||||
|
||||
def additional_attribute_setup(self):
|
||||
|
|
@ -164,9 +165,9 @@ class EavSetterAndGetterTests(TestCase):
|
|||
|
||||
self.additional_attribute_setup()
|
||||
|
||||
Registry.unregister(Patient)
|
||||
Registry.register(Patient, self.PatientEav)
|
||||
Registry.register(User, self.UserEav)
|
||||
eav.unregister(Patient)
|
||||
eav.register(Patient, self.PatientEav)
|
||||
eav.register(User, self.UserEav)
|
||||
|
||||
p = Patient.objects.create(name='Bob')
|
||||
|
||||
|
|
@ -187,8 +188,8 @@ class EavSetterAndGetterTests(TestCase):
|
|||
self.assertEqual(Patient.objects.get(pk=self.patient.pk).eav.city,
|
||||
'Tunis')
|
||||
|
||||
Registry.unregister(Patient)
|
||||
Registry.register(Patient, self.PatientEav)
|
||||
eav.unregister(Patient)
|
||||
eav.register(Patient, self.PatientEav)
|
||||
|
||||
p = Patient.objects.create(name='Patrick')
|
||||
p.eav.city = 'Paris'
|
||||
|
|
@ -204,9 +205,9 @@ class EavSetterAndGetterTests(TestCase):
|
|||
|
||||
self.additional_attribute_setup()
|
||||
|
||||
Registry.unregister(Patient)
|
||||
Registry.register(Patient, self.PatientEav)
|
||||
Registry.register(User, self.UserEav)
|
||||
eav.unregister(Patient)
|
||||
eav.register(Patient, self.PatientEav)
|
||||
eav.register(User, self.UserEav)
|
||||
|
||||
p = Patient.objects.create(name='Patrick')
|
||||
u = User.objects.create(username='John')
|
||||
|
|
@ -232,7 +233,7 @@ class EavSetterAndGetterTests(TestCase):
|
|||
|
||||
self.additional_attribute_setup()
|
||||
|
||||
Registry.unregister(Patient)
|
||||
eav.unregister(Patient)
|
||||
|
||||
class SubPatientEav(self.PatientEav):
|
||||
|
||||
|
|
@ -240,7 +241,7 @@ class EavSetterAndGetterTests(TestCase):
|
|||
def get_attributes(cls):
|
||||
return Attribute.objects.filter(slug='country')
|
||||
|
||||
Registry.register(Patient, SubPatientEav)
|
||||
eav.register(Patient, SubPatientEav)
|
||||
|
||||
self.patient.eav.city = 'Paris'
|
||||
self.patient.eav.country = 'USA'
|
||||
|
|
|
|||
Loading…
Reference in a new issue