From 4990c34c3f352368b4b30fb0f441ffb9352c5b96 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 14 May 2018 21:32:22 +0200 Subject: Add new to authors field for m2m images --- ishtar_common/widgets.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'ishtar_common/widgets.py') diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index e33669e19..442f12b9a 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -103,11 +103,12 @@ class SelectReadonlyField(forms.ChoiceField): class Select2Multiple(forms.SelectMultiple): def __init__(self, attrs=None, choices=(), remote=None, model=None, - available=None): + new=None, available=None): super(Select2Multiple, self).__init__(attrs, choices) self.remote = remote self.available = available self.model = model + self.new = new @property def media(self): @@ -152,7 +153,7 @@ class Select2Multiple(forms.SelectMultiple): attrs['class'] = klass if 'style' not in attrs: if attrs.get('full-width', None): - attrs['style'] = "width: 100%" + attrs['style'] = "width: calc(100% - 60px)" else: attrs['style'] = "width: 370px" @@ -195,7 +196,18 @@ class Select2Multiple(forms.SelectMultiple): options = "{" options += " containerCssClass: 'full-width'}" self.choices = choices - html = super(Select2Multiple, self).render(name, value, attrs) + + new, html = "", "" + if self.new: + html = u"
" + url_new = 'new-' + self.model.SLUG + url_new = reverse(url_new) + new = u'' \ + u'+
' % url_new + + html += super(Select2Multiple, self).render(name, value, attrs) + html += new html += """