From 120520e44d7dfcf3079bfdc9a118d28b5620cb14 Mon Sep 17 00:00:00 2001 From: Charlie Denton Date: Sun, 29 Oct 2017 00:44:48 +0100 Subject: [PATCH] Fix `add_media` util for Django 2.0 Neither `add_css` nor `add_js` exist in Django 2.0 because the method for adding `Media` classes together has changed. Ref: https://github.com/django/django/commit/c19b56f633e172b3c02094cbe12d28865ee57772 --- polymorphic/formsets/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/polymorphic/formsets/utils.py b/polymorphic/formsets/utils.py index 3d55f8b..5dac6a7 100644 --- a/polymorphic/formsets/utils.py +++ b/polymorphic/formsets/utils.py @@ -1,11 +1,17 @@ """ Internal utils """ +import django def add_media(dest, media): """ Optimized version of django.forms.Media.__add__() that doesn't create new objects. + + Only required for Django < 2.0 """ - dest.add_css(media._css) - dest.add_js(media._js) + if django.VERSION >= (2, 0): + dest += media + else: + dest.add_css(media._css) + dest.add_js(media._js)