Made Field.error_messages a cached property.
This speeds up field creation and reduces memory usage.
This commit is contained in:
parent
97d7990abd
commit
35c2474f16
|
@ -217,12 +217,7 @@ class Field(RegisterLookupMixin):
|
|||
|
||||
self._validators = list(validators) # Store for deconstruction later
|
||||
|
||||
messages = {}
|
||||
for c in reversed(self.__class__.__mro__):
|
||||
messages.update(getattr(c, "default_error_messages", {}))
|
||||
messages.update(error_messages or {})
|
||||
self._error_messages = error_messages # Store for deconstruction later
|
||||
self.error_messages = messages
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
|
@ -669,6 +664,14 @@ class Field(RegisterLookupMixin):
|
|||
"""
|
||||
return value
|
||||
|
||||
@cached_property
|
||||
def error_messages(self):
|
||||
messages = {}
|
||||
for c in reversed(self.__class__.__mro__):
|
||||
messages.update(getattr(c, "default_error_messages", {}))
|
||||
messages.update(self._error_messages or {})
|
||||
return messages
|
||||
|
||||
@cached_property
|
||||
def validators(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue