mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 13:06:30 -06:00
This commit is contained in:
parent
0094703609
commit
f86647dc28
@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
|
|
||||||
@ -56,8 +57,17 @@ def deserialize_object(model, fields, pk=None):
|
|||||||
the complement to serialize_object().
|
the complement to serialize_object().
|
||||||
"""
|
"""
|
||||||
content_type = ContentType.objects.get_for_model(model)
|
content_type = ContentType.objects.get_for_model(model)
|
||||||
|
m2m_data = {}
|
||||||
|
|
||||||
|
# Account for custom field data
|
||||||
if 'custom_fields' in fields:
|
if 'custom_fields' in fields:
|
||||||
fields['custom_field_data'] = fields.pop('custom_fields')
|
fields['custom_field_data'] = fields.pop('custom_fields')
|
||||||
|
|
||||||
|
# Pop any assigned tags to handle the M2M relationships manually
|
||||||
|
if is_taggable(model) and fields.get('tags'):
|
||||||
|
Tag = apps.get_model('extras', 'Tag')
|
||||||
|
m2m_data['tags'] = Tag.objects.filter(name__in=fields.pop('tags'))
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'model': '.'.join(content_type.natural_key()),
|
'model': '.'.join(content_type.natural_key()),
|
||||||
'pk': pk,
|
'pk': pk,
|
||||||
@ -65,4 +75,7 @@ def deserialize_object(model, fields, pk=None):
|
|||||||
}
|
}
|
||||||
instance = list(serializers.deserialize('python', [data]))[0]
|
instance = list(serializers.deserialize('python', [data]))[0]
|
||||||
|
|
||||||
|
# Apply any additional M2M assignments
|
||||||
|
instance.m2m_data.update(**m2m_data)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
Loading…
Reference in New Issue
Block a user