mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 04:56:29 -06:00
model_to_dict(): Convert object lists to PK lists
This commit is contained in:
parent
86ef739c12
commit
c9d0dcecf3
@ -22,6 +22,10 @@ def model_to_dict(instance, fields=None, exclude=None):
|
||||
if key.startswith('_'):
|
||||
del model_dict[key]
|
||||
|
||||
# Convert ManyToManyField to list of instance PKs
|
||||
elif model_dict[key] and type(model_dict[key]) in (list, tuple) and hasattr(model_dict[key][0], 'pk'):
|
||||
model_dict[key] = [obj.pk for obj in model_dict[key]]
|
||||
|
||||
if 'tags' in model_dict:
|
||||
model_dict['tags'] = ','.join(sorted([tag.name for tag in model_dict['tags']]))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user