Sfoglia il codice sorgente

Merge pull request #10103 from arthanson/art-10094

Fix #10094 - Contact Assignments Create and Add Another
Jeremy Stretch 3 anni fa
parent
commit
3110765d12

+ 7 - 0
netbox/netbox/views/generic/object_views.py

@@ -328,6 +328,12 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
         """
         return obj
 
+    def get_extra_addanother_params(self, request):
+        """
+        Return a dictionary of extra parameters to use on the Add Another button.
+        """
+        return {}
+
     #
     # Request handlers
     #
@@ -403,6 +409,7 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
 
                     # If cloning is supported, pre-populate a new instance of the form
                     params = prepare_cloned_fields(obj)
+                    params.update(self.get_extra_addanother_params(request))
                     if params:
                         if 'return_url' in request.GET:
                             params['return_url'] = request.GET.get('return_url')

+ 7 - 0
netbox/tenancy/views.py

@@ -1,4 +1,5 @@
 from django.contrib.contenttypes.models import ContentType
+from django.http import QueryDict
 from django.shortcuts import get_object_or_404
 
 from circuits.models import Circuit
@@ -365,6 +366,12 @@ class ContactAssignmentEditView(generic.ObjectEditView):
             instance.object = get_object_or_404(content_type.model_class(), pk=request.GET.get('object_id'))
         return instance
 
+    def get_extra_addanother_params(self, request):
+        return {
+            'content_type': request.GET.get('content_type'),
+            'object_id': request.GET.get('object_id'),
+        }
+
 
 class ContactAssignmentDeleteView(generic.ObjectDeleteView):
     queryset = ContactAssignment.objects.all()

+ 1 - 1
netbox/utilities/utils.py

@@ -285,7 +285,7 @@ def prepare_cloned_fields(instance):
     """
     # Generate the clone attributes from the instance
     if not hasattr(instance, 'clone'):
-        return QueryDict()
+        return QueryDict(mutable=True)
     attrs = instance.clone()
 
     # Prepare querydict parameters