Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Install

django-bananas is on PyPI, so just run:

pip install django-bananas

Compatibility

Currently bleeding edge, tested in

  • Django 1.8 under Python 3.4

pull requests welcome!

Examples

Models

TimeStampedModel

Abstract TimeStampedModel with date created/modified fields:

Use TimeStampedModel as base class for your model

from bananas.models import TimeStampedModel

class Book(TimeStampedModel):
    pass

the timestamps can be accessed on the model as

>>> book.date_created
>>> book.date_modified

UUIDModel

Abstract model that uses a Django 1.8 UUID field as the primary key.

from bananas.models import UUIDModel

class User(UUIDModel):
    display_name = models.CharField(max_length=255)
    email = models.EmailField()

>>> user.id
UUID('70cf1f46-2c79-4fc9-8cc8-523d67484182')

>>> user.pk
UUID('70cf1f46-2c79-4fc9-8cc8-523d67484182')

SecretField

Can be used to generate and store “safe” random bytes for authentication.

from bananas.models import SecretField

class User(models.Model):
    # Ask for 32 bytes and require 24 bytes from urandom
    token = SecretField(num_bytes=32, min_bytes=24)

>>> User.objects.create()  # Token is generated automatically
>>> user.token
'3076f884da827809e80ced236e8da20fa36d0c27dd036bdd4afbac34807e5cf1'

URLSecretField

An implementation of SecretField that generates an URL-safe base64 string instead of a hex representation of the random bytes.

from bananas.models import URLSecretField


class User(models.Model):
    # Generates an URL-safe base64 representation of the random value
    token = URLSecretField(num_bytes=32, min_bytes=24)

>>> user.token
'WOgrNwqFKOF_LsHorJy_hGpPepjvVH7Uar-4Z_K6DzU-'

ORM

New queryset.dicts() with field renaming through kwargs, and dot-dict style results:

from bananas.query import ExtendedQuerySet

class Book(TimeStampedModel):
    author = ForeignKey(Author)
    objects = Manager.from_queryset(ExtendedQuerySet)()

>>> book = Book.objects.dicts('id', author='author__name').first()
{'id': 1, 'author': 'Jonas'}
>>> book.author
'Jonas'

Admin

Custom django admin stylesheet.

# settings.py
INSTALLED_APPS = (
    'bananas',  # Needs to be before 'django.contrib.admin'
    'django.contrib.admin',
    ...
)

ADMIN = {
    'SITE_HEADER': 'Bananas',
    'SITE_TITLE': 'Bananas Admin',
    'INDEX_TITLE': 'Admin Panel',
    # 'BACKGROUND_COLOR': '#363c3f',
}
# your main urls.py
from bananas import admin

urlpatterns = [
    ...
    url(r'^admin/', include(admin.site.urls)),
]

Database URLs

Parse database information from a URL, kind of like SQLAlchemy.

Engines

Currently supported engines are:

URI scheme

Engine

pgsql, postgres, postgresql

django.db.backends.postgresql_psycopg2

mysql

django.db.backends.mysql

oracle

django.db.backends.oracle

sqlite, sqlite3

django.db.backends.sqlite3

You can add your own by running register(scheme, module_name) before parsing.

generate_conf_from_url(url)

Return a django-style database configuration based on url.

param url:

Database URL

return:

Django-style database configuration dict

Example:

>>> from bananas.url import generate_conf_from_url
>>> conf = database_conf_from_url(
...     'pgsql://joar:hunter2@5monkeys.se:4242/tweets/tweetschema'
...     '?hello=world')
>>> sorted(conf.items())  # doctest: +NORMALIZE_WHITESPACE
[('ENGINE', 'django.db.backends.postgresql_psycopg2'),
 ('HOST', '5monkeys.se'),
 ('NAME', 'tweets'),
 ('PARAMS', {'hello': 'world'}),
 ('PASSWORD', 'hunter2'),
 ('PORT', 4242),
 ('SCHEMA', 'tweetschema'),
 ('USER', 'joar')]

Download files

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

Source Distribution

django-bananas-1.0.9b2.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_bananas-1.0.9b2-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file django-bananas-1.0.9b2.tar.gz.

File metadata

File hashes

Hashes for django-bananas-1.0.9b2.tar.gz
Algorithm Hash digest
SHA256 e699d155e244f6e248988fac28eb9cd09c91048098d48502ab2968dad0704031
MD5 deb7580e03fbdde3746020179ec1aea3
BLAKE2b-256 2f3e8bb00ad71d253894a32243d8befdbfc22e3ca41cb3425352ee36bc81892a

See more details on using hashes here.

File details

Details for the file django_bananas-1.0.9b2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_bananas-1.0.9b2-py3-none-any.whl
Algorithm Hash digest
SHA256 99bafc1a918af5d5183d16c0f57d1197a103fa477ccc2b5942e55e1f6f291272
MD5 0b012f65336a9e1f35af7008b27cf227
BLAKE2b-256 246c053b81e47d5c82dfb53c3dbdf577bbe386d47655cb760a5c2f296ea6659e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page