Support for slugging from multiple fields

This commit is contained in:
Swen Kooij
2017-06-26 12:34:50 +03:00
parent 3b28a5e707
commit 51fc6959d2
3 changed files with 121 additions and 4 deletions

View File

@@ -19,3 +19,26 @@ def get_language_codes() -> List[str]:
lang_code
for lang_code, _ in settings.LANGUAGES
]
def resolve_object_property(obj, path: str):
"""Resolves the value of a property on an object.
Is able to resolve nested properties. For example,
a path can be specified:
'other.beer.name'
Raises:
AttributeError:
In case the property could not be resolved.
Returns:
The value of the specified property.
"""
value = obj
for path_part in path.split('.'):
value = getattr(value, path_part)
return value