Support Django 5.0
aliceni81 opened this issue · 3 comments
aliceni81 commented
The current version is incompatible with Django 5.0.
There is no _get_flatchoices in django's CharField anymore, instead Django provides flatchoices directly. Therefore, the following code in db/fields.py should be removed.
def _get_flatchoices(self):
flat_choices = super(MultiSelectField, self)._get_flatchoices()
class MSFFlatchoices(list):
# Used to trick django.contrib.admin.utils.display_for_field into
# not treating the list of values as a dictionary key (which errors
# out)
def __bool__(self):
return False
__nonzero__ = __bool__
return MSFFlatchoices(flat_choices)
flatchoices = property(_get_flatchoices)
ssherchan08 commented
I was also wondering why my data was not being fetched. Spent hours debugging. Thanks for this! It helped me save so much time.
symphoton commented
In my application, simply removing those lines breaks the display in the admin view. I recommend keeping the code, but replacing
flat_choices = super(MultiSelectField, self)._get_flatchoices()
by
flat_choices = super(MultiSelectField, self).flatchoices
or
try:
flat_choices = super(MultiSelectField, self).flatchoices
except AttributeError:
flat_choices = super(MultiSelectField, self)._get_flatchoices()
for backwards compatibility
sadra-allahyari commented
Big thanks, everyone! I was struggling to figure out how to fix it.