Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sortedm2m/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django import forms
from django.conf import settings
from django.utils import translation
from django.contrib.admin.widgets import AutocompleteSelectMultiple
from django.utils import translation


class OrderedAutocomplete(AutocompleteSelectMultiple):
def optgroups(self, name, value, attr=None):
Expand Down Expand Up @@ -48,7 +49,7 @@ def optgroups(self, name, value, attr=None):
class Media:
extra = "" if settings.DEBUG else ".min"
lang = translation.get_language()
js = (
js = (
"admin/js/vendor/jquery/jquery%s.js" % extra,
"admin/js/vendor/select2/select2.full%s.js" % extra,
) + (
Expand Down
2 changes: 1 addition & 1 deletion sortedm2m/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def set(self, objs, *, clear=False, through_defaults=None):
# Force evaluation of `objs` in case it's a queryset whose value
# could be affected by `manager.clear()`. Refs #19816.
# objs = tuple(objs)

db = router.db_for_write(self.through, instance=self.instance)
with transaction.atomic(using=db, savepoint=False):
old_ids = list(
Expand Down
6 changes: 4 additions & 2 deletions sortedm2m/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@


class SortedCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
template_name = 'sortedm2m/sorted_checkbox_select_multiple_widget.html'

class Media:
js = (
'admin/js/jquery.init.js',
Expand Down Expand Up @@ -72,7 +74,7 @@ def render(self, name, value, attrs=None, choices=(), renderer=None): # pylint:
selected = ordered

html = render_to_string(
'sortedm2m/sorted_checkbox_select_multiple_widget.html',
self.template_name,
{'selected': selected, 'unselected': unselected})
return mark_safe(html)

Expand Down Expand Up @@ -106,4 +108,4 @@ def has_changed(self, initial, data):
class SortedCheckboxMultipleChoiceField(SortedMultipleChoiceField):
widget = SortedCheckboxSelectMultiple