audit: save model's name or string representation

This commit is contained in:
Jens Langhammer 2020-02-23 15:04:30 +01:00
parent 382e563590
commit 074cde7cd5
1 changed files with 5 additions and 1 deletions

View File

@ -33,11 +33,15 @@ def sanitize_dict(source: Dict[Any, Any]) -> Dict[Any, Any]:
source[key] = sanitize_dict(value)
elif isinstance(value, models.Model):
model_content_type = ContentType.objects.get_for_model(value)
name = str(value)
if hasattr(value, "name"):
name = value.name
source[key] = sanitize_dict(
{
"app": model_content_type.app_label,
"name": model_content_type.model,
"model_name": model_content_type.model,
"pk": value.pk,
"name": name,
}
)
elif isinstance(value, UUID):