Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up, update for Django 5, and fix tests #148

Merged
merged 4 commits into from
May 21, 2024
Merged

Conversation

blag
Copy link
Collaborator

@blag blag commented May 20, 2024

  • Remove reverse compatibility code for Python < 3
  • Remove reverse compatibility code for Django < 4.1
  • Add compatibility for Django 5+
  • Remove South migration
  • Fix tests in example project

This removes backwards compatibility code that @goinnn has previously indicated they would rather keep. But the Python ecosystem has moved on so far since Django 1 and 2 and Python 2 that I think it's time to stop supporting those.

Closes #142, #146.

@@ -54,14 +55,17 @@ def __init__(self, *args, **kwargs):
self.max_choices = kwargs.pop('max_choices', None)
super(MultiSelectField, self).__init__(*args, **kwargs)
self.max_length = get_max_length(self.choices, self.max_length)
self.validators[0] = MaxValueMultiFieldValidator(self.max_length)
self.validators.append(MaxValueMultiFieldValidator(self.max_length))
Copy link

@arcticlinux arcticlinux Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the best place to mention this, but I was working on this last year, and this changes how the validators work.

The original removes/replaces the existing CharField MaxLengthValidator.

Appending to the validators means that both the CharField MaxLengthValidator and MaxValueMultiFieldValidator are present. Previously if you specified your model without a max_length the max length would be set the length of the longest choice or to the default 200 in get_max_length. Appending causes a validation error when django.core.validators MaxLengthValidator.compare tries to compare model's max_length (None) if you don't supply a max_length in the model.

I changed my fork to use:

self.validators = [v for v in self.validators if not isinstance(v, validators.MaxLengthValidator)]
self.max_length = get_max_length(self.choices, self.max_length)
self.validators.append(MaxValueMultiFieldValidator(self.max_length))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you submit a PR?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Django 5.0
3 participants