Skip to main content

A simple Django app that provides Indonesian Bank models and fields.

Project description

A Django application that provides Indonesian bank choices for use with forms and a country field for models.


  1. Run pip install p1-bank
  2. Add 'bank' to INSTALLED_APPS in
  3. Run python migrate to create banks models

Bank Model

A model of bank that holds all banks in Indonesia.

Supports long name, short name, bank code, and branch code.

>>> from django.apps import apps
>>> Bank = apps.get_model('bank', 'Bank')
>>> bank = Bank.objects.get(short_name='BANK BCA')
>>> bank.long_name
>>> bank.short_name
>>> bank.bank_code
>>> bank.branch_code
>>> bank.bi_code

It is possible to get a bank object from bi code:

>>> Bank.objects.get_by_bi_code('0140397')
<Bank: BANK BCA>

or upsert (update or create) from list with header:

>>> Bank.objects.get(bank_code='200')
<Bank: BANK BTN>
>>> bank_list = [
        ['bank_code', 'short_name'],
        ['200', 'BTN']
>>> Bank.objects.upsert_from_list_with_header(bank_list)
>>> Bank.objects.get(bank_code='200')
<Bank: BTN>

Bank Field

BankField is based on Django’s ForeignKey, a relationship to Bank model.

Consider an Account model using a BankField:

from django.db import models
from p1_bank.fields import BankField

class Account(models.Model):
    name = models.CharField(max_length=100)
    bank = BankField(related_name='accounts')

Any Account instance will have a bank attribute that you can use to identify account’s bank:

>>> bank = Bank.objects.get(short_name='BANK BCA')
>>> account = Account.objects.create(name='Kania', bank=bank)

Bank Factories

You may use bank factories to support your test (requires factory_boy)

>>> from bank.factories import BankFactory
>>> BankFactory()
<Bank: Bank X00>
>>> BankFactory()
<Bank: Bank X01>
>>> bank301 = BankFactory(bank_code='301')
>>> bank301.bank_code

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for p1-bank, version 0.2.45508391
Filename, size File type Python version Upload date Hashes
Filename, size p1_bank-0.2.45508391-py2-none-any.whl (14.8 kB) File type Wheel Python version py2 Upload date Hashes View hashes
Filename, size p1-bank-0.2.45508391.tar.gz (10.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page