audit: fix error when trying to save models with UUID as PK

This commit is contained in:
Jens Langhammer
2020-01-02 13:00:16 +01:00
parent 865435fb25
commit 387f3c981f
2 changed files with 30 additions and 8 deletions

View File

@ -1,5 +1,6 @@
"""passbook audit models"""
from enum import Enum
from uuid import UUID
from inspect import getmodule, stack
from typing import Optional, Dict, Any
@ -32,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)
source[key] = {
"app": model_content_type.app_label,
"name": model_content_type.model,
"pk": value.pk,
}
source[key] = sanitize_dict(
{
"app": model_content_type.app_label,
"name": model_content_type.model,
"pk": value.pk,
}
)
elif isinstance(value, UUID):
source[key] = value.hex
return source