From 9a4c8f3ad30929bba9e3d5882d6528d9b2521f7e Mon Sep 17 00:00:00 2001 From: Zach Taylor Date: Thu, 22 Oct 2020 15:53:34 -0500 Subject: [PATCH] Add instance parameter to config get_attributes --- eav/models.py | 4 +++- eav/registry.py | 2 +- tests/attributes.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/eav/models.py b/eav/models.py index 3321616..ca09c36 100644 --- a/eav/models.py +++ b/eav/models.py @@ -503,7 +503,9 @@ class Entity(object): Return a query set of all :class:`Attribute` objects that can be set for this entity. """ - return self.instance._eav_config_cls.get_attributes().order_by('display_order') + return self.instance._eav_config_cls.get_attributes( + instance=self.instance + ).order_by('display_order') def _hasattr(self, attribute_slug): """ diff --git a/eav/registry.py b/eav/registry.py index 5216081..91f3cfd 100644 --- a/eav/registry.py +++ b/eav/registry.py @@ -33,7 +33,7 @@ class EavConfig(object): generic_relation_related_name = None @classmethod - def get_attributes(cls): + def get_attributes(cls, instance=None): """ By default, all :class:`~eav.models.Attribute` object apply to an entity, unless you provide a custom EavConfig class overriding this. diff --git a/tests/attributes.py b/tests/attributes.py index d1b06d7..74674df 100644 --- a/tests/attributes.py +++ b/tests/attributes.py @@ -24,7 +24,7 @@ class Attributes(TestCase): generic_relation_related_name = 'encounters' @classmethod - def get_attributes(cls): + def get_attributes(cls, instance=None): return Attribute.objects.filter(slug__contains='a') eav.register(Encounter, EncounterEavConfig) @@ -76,7 +76,7 @@ class Attributes(TestCase): def test_illegal_assignemnt(self): class EncounterEavConfig(EavConfig): @classmethod - def get_attributes(cls): + def get_attributes(cls, instance=None): return Attribute.objects.filter(datatype=Attribute.TYPE_INT) eav.unregister(Encounter)