IBAN field for django with validation and optional postgresql in database constraint checking
Project description
Django iban field with validators and optional postgresql in base constraint checking. This is expected to work with django 1.8 and later.
Installation
Install django-iban-field like you would install any other pypi package:
pip install django-iban-field
Configuration and usage
add django_iban to the list of INSTALLED_APPS in your settings.py
use in models.py:
from django_iban.fields import IBANField ... class MyModel(models.Model): iban = IBANField(enforce_database_constraint=True, unique=True)
The enable_databse_constraint option will add a function named is_valid_iban to your database and use it the enforce the database type checking. This option will have an effect only if you are using the postgreql backend and have the plpython extension enabled on your database.
Utilities
Other than the django field, you will find a generator class to use if you want to generate valid IBAN values:
from django_iban.generator import IBANGenerator .... generator = IBANGenerator() # A complete random IBAN valid_iban = generator.generate() # But you can specify the country valid_iban = generator.generate(country_code='DE') # Or the bank and account valid_iban = generator.generate(country_code='DE', bank=XXXX, account=XXXX)
You cannot of course just pass the bank and the account without the country, and if you pass one or both of these values will then check for their validity, compute the checksum and return the valid IBAN.
You may also be intereseted in the IBANSpecification class that contains all the format specification and the checksum facility:
from django_iban.specification import IBANSpecification from django_iban.specification import IBAN_SPECIFICATION_CONFIG .... country_specification = IBAN_SPECIFICATION_CONFIG['TN'] print(country_specification.bank_field_length) # 5 print(country_specification.bank_regex) #[0-9]{2}[0-9]{3} print(country_specification.iban_regex) #[A-Z]{2}[0-9]{2}[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}
Inspiration
This module take it’s inspiration and some of the ideas from the django-localflavor IBanField and the specification from tom’s cafe
Example
You can find a running example of this field in this demo django application, and if you are super lazy you can just get my vagrant bootstraper script that will setup a full working vm using that project. You just have to have vagrant and openssl installed (tested on Fedora but should work with any other modern linux or mac):
curl https://raw.githubusercontent.com/Chedi/DjangoVagrantBootsraper/master/bootstrap.sh | bash
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file django_iban_field-0.8-py2.py3-none-any.whl
.
File metadata
- Download URL: django_iban_field-0.8-py2.py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d11eacb49b939702aa169aa0a3c9880970ed087c236279c32c26f86c7e10092 |
|
MD5 | d1f20893e00f834ea5b6451646d97ba5 |
|
BLAKE2b-256 | d9afdc01e6f2ea4b2b282e01936ba70d18e215ea5527c1a58432b40251692429 |