diff --git a/modelcluster/utils.py b/modelcluster/utils.py index ae94240..b16694c 100644 --- a/modelcluster/utils.py +++ b/modelcluster/utils.py @@ -66,9 +66,17 @@ def get_model_field(model, name): subject_model=subject_model, ) ) - if hasattr(field, "related_model"): + if getattr(field, "related_model", None): traversals.append(TraversedRelationship(subject_model, field)) subject_model = field.related_model + else: + raise FieldDoesNotExist( + "Failed attempting to traverse from {from_field} to '{to_field}'." + .format( + from_field=subject_model._meta.app_label + '.' + field.name, + to_field=field_name, + ) + ) try: field = subject_model._meta.get_field(field_name) except FieldDoesNotExist: