diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 482c7181183..81db2a24f3d 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -82,7 +82,9 @@ class Media(StrAndUnicode): def add_css(self, data): if data: for medium, paths in data.items(): - self._css.setdefault(medium, []).extend([path for path in paths if path not in self._css[medium]]) + for path in paths: + if not self._css.get(medium) or path not in self._css[medium]: + self._css.setdefault(medium, []).append(path) def __add__(self, other): combined = Media() diff --git a/tests/regressiontests/forms/media.py b/tests/regressiontests/forms/media.py index f47875db344..d715fb4d801 100644 --- a/tests/regressiontests/forms/media.py +++ b/tests/regressiontests/forms/media.py @@ -112,15 +112,17 @@ media_tests = r""" -# Regression check for #12879: specifying the same JS file multiple -# times in a single Media instance should result in that file only -# being included once. +# Regression check for #12879: specifying the same CSS or JS file +# multiple times in a single Media instance should result in that file +# only being included once. >>> class MyWidget4(TextInput): ... class Media: +... css = {'all': ('/path/to/css1', '/path/to/css1')} ... js = ('/path/to/js1', '/path/to/js1') >>> w4 = MyWidget4() >>> print w4.media +