Skip to content

Commit

Permalink
correct set choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Ben Makhlouf committed Mar 13, 2024
1 parent 3389048 commit 20b7e15
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions smart_selects/form_fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
from django.apps import apps
from django.forms.models import ModelChoiceField, ModelMultipleChoiceField
from django.forms import ChoiceField
Expand Down Expand Up @@ -59,7 +60,10 @@ def _get_choices(self):
choices = super(ChainedModelChoiceField, self)._get_choices()
return choices

choices = property(_get_choices, ChoiceField._set_choices)
if django.VERSION >= (5, 0):
choices = property(_get_choices, ChoiceField.choices)
else:
choices = property(_get_choices, ChoiceField._set_choices)


class ChainedManyToManyField(ModelMultipleChoiceField):
Expand Down Expand Up @@ -143,4 +147,7 @@ def _get_choices(self):
def make_choice(self, obj):
return (obj.pk, " " + self.label_from_instance(obj))

choices = property(_get_choices, ChoiceField._set_choices)
if django.VERSION >= (5, 0):
choices = property(_get_choices, ChoiceField.choices)
else:
choices = property(_get_choices, ChoiceField._set_choices)

0 comments on commit 20b7e15

Please sign in to comment.