django-pursed
A simple wallet django application
Creating a New Wallet
A wallet is owned by a user. Should you be using a custom user model, the wallet should still work properly as it the wallet points to settings.AUTH_USER_MODEL.
from wallet.models import Wallet
# wallets are owned by users.
wallet = user.wallet_set.create()
Despositing a balance to a wallet
from django.db import transaction
with transaction.atomic():
# We need to lock the wallet first so that we're sure
# that nobody modifies the wallet at the same time
# we're modifying it.
wallet = Wallet.select_for_update().get(pk=wallet.id)
wallet.deposit(100) # amount
Withdrawing a balance from a wallet
from django.db import transaction
with transaction.atomic():
# We need to lock the wallet first so that we're sure
# that nobody modifies the wallet at the same time
# we're modifying it.
wallet = Wallet.select_for_update().get(pk=wallet.id)
wallet.withdraw(100) # amount
Withdrawing with an insufficient balance
When a user tries to withdraw from a wallet with an amount greater than its balance, the transaction raises a wallet.errors.InsufficientBalance error.
# wallet.current_balance # 50
# This raises an wallet.errors.InsufficentBalance.
wallet.withdraw(100)
This error inherits from django.db.IntegrityError so that when it is raised, the whole transaction is automatically rolled-back.
Transferring between wallets
One can transfer a values between wallets. It uses withdraw and deposit internally. Should the sending wallet have an insufficient balance, wallet.errors.InsufficientBalance is raised.
with transaction.atomic():
wallet = Wallet.select_for_update().get(pk=wallet_id)
transfer_to_wallet = Wallet.select_for_update().get(pk=transfer_to_wallet_id)
wallet.transfer(transfer_to_wallet, 100)
CURRENCY_STORE_FIELD
The CURRENCY_STORE_FIELD is a django field class that contains how the fields should be stored. By default, it uses django.models.BigIntegerField. It was chosen that way for simplicity - just make cents into your smallest unit (0.01 -> 1, 1.00 -> 100).
You can change this to decimal by adding this to your settings.py:
# settings.py
CURRENCY_STORE_FIELD = models.DecimalField(max_digits=10, decimal_places=2)
You need to run ./manage.py makemigrations after that.
Metadata
Release files for django-pursed 0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-pursed-0.9.linux-x86_64.tar.gz | 11.5 kB | Without provenance | Details for django-pursed-0.9.linux-x86_64.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_pursed-0.9-py3-none-any.whl | Python 3 | none | any | Details for django_pursed-0.9-py3-none-any.whl |
| django_pursed-0.9-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_pursed-0.9-py2.py3-none-any.whl |
Total release size: 45.2 kB
Release files / django-pursed-0.9.linux-x86_64.tar.gz
| Download URL | django-pursed-0.9.linux-x86_64.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca20aab4a01730edf373c07ef184275725c4031e4fb0d8500f94b2c0925c733c
|
|
BLAKE2b-256 checksum How to use checksums |
2e58baa3761e86a132dc71f6b03c4bbc31bcc71becffd2cccc2435f3028b7242
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_pursed-0.9-py3-none-any.whl
| Download URL | django_pursed-0.9-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7ea21139ef912fe4e04efbd41be0c8a621f9ae17a7762193581c869c5208b04f
|
|
BLAKE2b-256 checksum How to use checksums |
c4a4b0bb1e9556abfa63a5c5759da105eee3484828266039afb5a1309310f13d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_pursed-0.9-py2.py3-none-any.whl
| Download URL | django_pursed-0.9-py2.py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b225c50cd2698fa85f3659bb22c4aee817bb9fa49d06a6f9cb5ec88482f27582
|
|
BLAKE2b-256 checksum How to use checksums |
5c46dd34fb25e153346c4ae55a3a5f8ac9c0e02d4f18871af51d01ac031fe899
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-pursed 0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.