1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#10052: Serialize date fields

This commit is contained in:
jeremystretch
2022-11-15 15:44:36 -05:00
parent 87fd09ca8b
commit 23077821f6
2 changed files with 34 additions and 24 deletions

View File

@@ -302,6 +302,8 @@ class CustomField(CloningMixin, ExportTemplatesMixin, WebhooksMixin, ChangeLogge
"""
if value is None:
return value
if self.type == CustomFieldTypeChoices.TYPE_DATE and type(value) is date:
return value.isoformat()
if self.type == CustomFieldTypeChoices.TYPE_OBJECT:
return value.pk
if self.type == CustomFieldTypeChoices.TYPE_MULTIOBJECT:
@@ -314,6 +316,11 @@ class CustomField(CloningMixin, ExportTemplatesMixin, WebhooksMixin, ChangeLogge
"""
if value is None:
return value
if self.type == CustomFieldTypeChoices.TYPE_DATE:
try:
return date.fromisoformat(value)
except ValueError:
return value
if self.type == CustomFieldTypeChoices.TYPE_OBJECT:
model = self.object_type.model_class()
return model.objects.filter(pk=value).first()