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 some magic methods for Money class #747

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kairkhan24
Copy link

No description provided.

@kairkhan24 kairkhan24 marked this pull request as draft January 26, 2024 09:30
@kairkhan24 kairkhan24 changed the title Add magic methods float and int for Money class Add some magic methods for Money class Jan 26, 2024
@kairkhan24 kairkhan24 marked this pull request as ready for review January 26, 2024 09:41
Copy link
Contributor

@benjaoming benjaoming left a comment

Choose a reason for hiding this comment

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

Hi there!

It'd be good if you can state what you are trying to achieve here.

As you can see from the existing implementation of __add__ and __sub__, we want to ensure that the currency is the same on both Money objects before any further arithmetic.

The definition of the parent class might help you here, as many arithmetic methods are already defined: https://github.com/py-moneyed/py-moneyed/blob/master/src/moneyed/classes.py#L158

@kairkhan24
Copy link
Author

kairkhan24 commented Jan 26, 2024

Hi there!

It'd be good if you can state what you are trying to achieve here.

As you can see from the existing implementation of __add__ and __sub__, we want to ensure that the currency is the same on both Money objects before any further arithmetic.

The definition of the parent class might help you here, as many arithmetic methods are already defined: https://github.com/py-moneyed/py-moneyed/blob/master/src/moneyed/classes.py#L158

Ok, i understood you, can we pass only float and int methods here?

And also is possible to write own CustomMoney inherited from Money class and pass it to MoneyField?

@benjaoming
Copy link
Contributor

And also is possible to write own CustomMoney inherited from Money class and pass it to MoneyField?

I don't know, I unfortunately haven't tried this and wouldn't know what pattern to follow to achieve it. You might have to subclass a lot of stuff.

@benjaoming
Copy link
Contributor

Ok, i understood you, can we pass only float and int methods here?

I mean, if you want to improve and extend the functionality, that's great 🥳 It was more to ensure that however it's done, it also includes the currency as you can see from existing methods.

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.

None yet

2 participants