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

Add a DB converter for the model field #559

Merged
merged 1 commit into from
Jul 17, 2023

Conversation

francoisfreitag
Copy link
Collaborator

@francoisfreitag francoisfreitag commented May 15, 2023

@francoisfreitag francoisfreitag merged commit 19b82b1 into stefanfoulis:main Jul 17, 2023
@francoisfreitag francoisfreitag deleted the ff/values-list branch July 17, 2023 07:25
@kalekseev
Copy link

This is a breaking change, would be better to release it in v8...

@francoisfreitag
Copy link
Collaborator Author

Oops, that’s right. Sorry for the trouble! I’ll update the release note text to highlight that.

@chris-erickson
Copy link

How would we get the old behavior back?

@francoisfreitag
Copy link
Collaborator Author

francoisfreitag commented Nov 21, 2023

Depending on what you expect, I would say either:

  • call str() on the PhoneNumber object (or the property for a specific format, such as .as_international, .as_e164, ...)
  • subclass the phonenumber_field.modelfields.PhoneNumberField and implement from_db_value() as
      def from_db_value(self, value, expression, connection):
          return value

EDIT: Thanks @Neumsy for pointing out that I mixed up the call to remove (to_python) with the field method name (from_db_value).

@Neumsy
Copy link

Neumsy commented Mar 13, 2024

  • subclass the phonenumber_field.modelfields.PhoneNumberField and implement to_python() as
      def to_python(self, value):
          return value

When using this method, shouldn't the suggestion be to override the from_db_value method? The calling to_python method is not part of the class inheritance, so overriding it in the class doesn't produce the desired outcome.

    def from_db_value(self, value, expression, connection):
        return str(value)

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

Successfully merging this pull request may close these issues.

4 participants