From 599f2f79e22aaa475e45b72768babf70ac71a6b2 Mon Sep 17 00:00:00 2001 From: David Smith Date: Sun, 30 Aug 2020 13:44:39 +0100 Subject: Fixed #30563 -- Optimized form Media by removing duplicated assets when adding. --- django/forms/widgets.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'django/forms') diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 7ea3c7bcbf..1b1c1439cb 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -146,8 +146,14 @@ class Media: def __add__(self, other): combined = Media() - combined._css_lists = self._css_lists + other._css_lists - combined._js_lists = self._js_lists + other._js_lists + combined._css_lists = self._css_lists[:] + combined._js_lists = self._js_lists[:] + for item in other._css_lists: + if item and item not in self._css_lists: + combined._css_lists.append(item) + for item in other._js_lists: + if item and item not in self._js_lists: + combined._js_lists.append(item) return combined -- cgit v1.3