Detect type of SlugRelatedField with readonly=True (#83)

* Added test for #82 - readonly SlugRelatedField not showing format uuid
* Added ArticleGroup model
* Added example of SlugRelatedField to a uuid field with and without readonly
* Check remote_field.model in get_related_model

Closes #82.
This commit is contained in:
John Carter
2018-03-11 00:29:20 +13:00
committed by Cristi Vîjdea
parent 2c459024d1
commit fb240f6a5b
6 changed files with 67 additions and 3 deletions
+5 -1
View File
@@ -161,7 +161,11 @@ def get_related_model(model, source):
:return: related model or ``None``
"""
try:
return getattr(model, source).rel.related_model
descriptor = getattr(model, source)
try:
return descriptor.rel.related_model
except Exception:
return descriptor.field.remote_field.model
except Exception: # pragma: no cover
return None