mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Fix tag population for object cloning
This commit is contained in:
parent
5fd5dbab7b
commit
bf7bd68b6a
@ -4,8 +4,6 @@ from collections import OrderedDict
|
|||||||
|
|
||||||
from django.core.serializers import serialize
|
from django.core.serializers import serialize
|
||||||
from django.db.models import Count, OuterRef, Subquery
|
from django.db.models import Count, OuterRef, Subquery
|
||||||
from django.http import QueryDict
|
|
||||||
from django.http.request import HttpRequest
|
|
||||||
from jinja2 import Environment
|
from jinja2 import Environment
|
||||||
|
|
||||||
from dcim.choices import CableLengthUnitChoices
|
from dcim.choices import CableLengthUnitChoices
|
||||||
@ -220,7 +218,7 @@ def prepare_cloned_fields(instance):
|
|||||||
Compile an object's `clone_fields` list into a string of URL query parameters. Tags are automatically cloned where
|
Compile an object's `clone_fields` list into a string of URL query parameters. Tags are automatically cloned where
|
||||||
applicable.
|
applicable.
|
||||||
"""
|
"""
|
||||||
params = {}
|
params = []
|
||||||
for field_name in getattr(instance, 'clone_fields', []):
|
for field_name in getattr(instance, 'clone_fields', []):
|
||||||
field = instance._meta.get_field(field_name)
|
field = instance._meta.get_field(field_name)
|
||||||
field_value = field.value_from_object(instance)
|
field_value = field.value_from_object(instance)
|
||||||
@ -231,16 +229,15 @@ def prepare_cloned_fields(instance):
|
|||||||
|
|
||||||
# Omit empty values
|
# Omit empty values
|
||||||
if field_value not in (None, ''):
|
if field_value not in (None, ''):
|
||||||
params[field_name] = field_value
|
params.append((field_name, field_value))
|
||||||
|
|
||||||
# Copy tags
|
# Copy tags
|
||||||
if is_taggable(instance):
|
if is_taggable(instance):
|
||||||
params['tags'] = ','.join([t.name for t in instance.tags.all()])
|
for tag in instance.tags.all():
|
||||||
|
params.append(('tags', tag.pk))
|
||||||
|
|
||||||
# Concatenate parameters into a URL query string
|
# Concatenate parameters into a URL query string
|
||||||
param_string = '&'.join(
|
param_string = '&'.join([f'{k}={v}' for k, v in params])
|
||||||
['{}={}'.format(k, v) for k, v in params.items()]
|
|
||||||
)
|
|
||||||
|
|
||||||
return param_string
|
return param_string
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user