soft_get(obj, field_base_name, dict_=False, case_sensitive=False, best_match=True, dont_include=None)¶
This function used for cases that we want to get some attribute that we either know only few parts of its name or want to prevent from case issues.
Imagine you have a relationships table and you want to get ‘image’ field. Since sometimes the exact name of the field is changing among versions, pages, etc. it could be appear as ‘Images’, ‘Image’, ‘Container Images’, Containers Images’, etc. Since we don’t care for the exact name and know that ‘image’ is a unique in the table, we can use this function to prevent from this complexity.
- obj (*) – The object which we want to get the attribute
- field_base_name (*) – The base name, a string that we know for sure that is a sub-string of the target field
- dict (*) – Whether this is a dict AND we want to perform the same functionality on its keys
- case_sensitive (*) – Whether the search is a sensitive case.
- best_match (*) –
- If True: in case that it found more than 1 match field,
- it will take the closest one
- If False: in case that it found more than 1 match field,
- it will raise an error
- dont_include (*) – Strings that should not be a part of the field. Used to prevent cases like: soft_get(obj, ‘image’) -> obj.image_registry
The value of the target attribute