Update custom widget
Django 3.1 updated ModelChoiceIterator behaviour
This commit is contained in:
parent
eb9bc2c692
commit
96dea12d1f
1 changed files with 8 additions and 1 deletions
|
|
@ -12,7 +12,14 @@ class RulesWidget(CheckboxSelectMultiple):
|
||||||
|
|
||||||
def create_option(self, *args, **kwargs):
|
def create_option(self, *args, **kwargs):
|
||||||
option = super().create_option(*args, **kwargs)
|
option = super().create_option(*args, **kwargs)
|
||||||
instance = self.choices.queryset.get(pk=option["value"])
|
|
||||||
|
# see https://docs.djangoproject.com/en/3.1/releases/3.1/#id1
|
||||||
|
try:
|
||||||
|
pk = int(option["value"])
|
||||||
|
except TypeError:
|
||||||
|
pk = option["value"].value
|
||||||
|
|
||||||
|
instance = self.choices.queryset.get(pk=pk)
|
||||||
|
|
||||||
if self.category and instance.category:
|
if self.category and instance.category:
|
||||||
option["selected"] = self.category.pk == instance.category.pk
|
option["selected"] = self.category.pk == instance.category.pk
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue