Add instance parameter to config get_attributes

This commit is contained in:
Zach Taylor 2020-10-22 15:53:34 -05:00
parent 1f629506a8
commit 9a4c8f3ad3
3 changed files with 6 additions and 4 deletions

View file

@ -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):
"""

View file

@ -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.

View file

@ -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)