15 Django packages that extend the functionality of existing field type or add new field types

Django-audiofield

Django-audiofield - JavaScript

163

Django-Audiofield is a simple app that allows Audio files upload, management and conversion to different audio format (mp3, wav & ogg), which also makes it easy to play audio files into your Django application.

git clone git://git.libav.org/libav.git
cd libav
sudo ./configure --disable-yasm
sudo make
sudo make install
Django-audiofield

 

Django-bitfield/

Django-bitfield/ - Python

361

A BitField extension for Django Models

from bitfield import BitField

class MyModel(models.Model):
    flags = BitField(flags=(
        'awesome_flag',
        'flaggy_foo',
        'baz_bar',
    ))

 

Django-countries/

Django-countries - Python

1.1k

A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Consider the following model using a CountryField:

from django.db import models
from django_countries.fields import CountryField

class Person(models.Model):
    name = models.CharField(max_length=100)
    country = CountryField()
country-codes django python

 

Django-enumfield/

Django-enumfield - Python

187

Custom Django field for using enumerations of named constants

Create an Enum-class and pass it as first argument to the Django model EnumField.

from django.db import models
from django_enumfield import enum


class BeerStyle(enum.Enum):
    LAGER = 0
    STOUT = 1
    WEISSBIER = 2


class Beer(models.Model):
    style = enum.EnumField(BeerStyle, default=BeerStyle.LAGER)


# Use .get to get enum values from either name or ints
print(BeerStyle.get("LAGER"))  # <BeerStyle.LAGER: 0>
print(BeerStyle.get(1))  # <BeerStyle.STOUT: 1>
print(BeerStyle.get(BeerStyle.WEISSBIER))  # <BeerStyle.WEISSBIER: 2>

# It's also possible to use the normal enum way to get the value
print(BeerStyle(1))  # <BeerStyle.STOUT: 1>
print(BeerStyle["LAGER"])  # <BeerStyle.LAGER: 0>

# The enum value has easy access to their value and name
print(BeerStyle.LAGER.value)  # 0
print(BeerStyle.LAGER.name)  # "LAGER"
django django-rest-framework enum python

 

A package to handle images in django

 

Automated image processing for Django. Currently v4.0

The easiest way to use define an image spec is by using an ImageSpecField on your model class:

from django.db import models
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill

class Profile(models.Model):
    avatar = models.ImageField(upload_to='avatars')
    avatar_thumbnail = ImageSpecField(source='avatar',
                                      processors=[ResizeToFill(100, 50)],
                                      format='JPEG',
                                      options={'quality': 60})

profile = Profile.objects.all()[0]
print(profile.avatar_thumbnail.url)    # > /media/CACHE/images/982d5af84cddddfd0fbf70892b4431e4.jpg
print(profile.avatar_thumbnail.width)  # > 100

 

Django-jsonfield

Django-jsonfield - Python

27

(Maintenance mode only) Cross-database JSON field for Django models.

Then use the field in your models:

from django.db import models
import jsonfield

class MyModel(models.Model):
    the_json = jsonfield.JSONField()

 

Django-location-field/

Django-location-field - JavaScript

469

Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox

Features

  • Support for multiple map engines, like Google Maps, OpenStreetMap and Mapbox.
  • Support for multiple search engines, like Google, Nominatim, Yandex and Addok.
  • Works with both Spatial and non-Spatial databases.

Basic usage (using Spatial Database)

from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
from location_field.models.spatial import LocationField

class Place(models.Model):
    city = models.CharField(max_length=255)
    location = LocationField(based_fields=['city'], zoom=7, default=Point(1.0, 1.0))
Django-location-field/

 

 

MAC address Model Field & Form Field for Django apps

>>> from netaddr import EUI, mac_bare
>>> from macaddress import format_mac

>>> mac = EUI('00:12:3c:37:64:8f')
>>> format_mac(mac, mac_bare)
'00123C37648F'
>>> format_mac(mac, 'netaddr.mac_cisco')
'0012.3c37.648f'
django macaddress python python3

 

Money fields for Django forms and models.

Use as normal model fields:

from djmoney.models.fields import MoneyField
from django.db import models


class BankAccount(models.Model):
    balance = MoneyField(max_digits=14, decimal_places=2, default_currency='USD')
django money python

 

Django-phonenumber-field/

Django-phonenumber-field - Python

1.2k

A django model and form field for normalised phone numbers using python-phonenumbers

from phonenumber_field.modelfields import PhoneNumberField

class MyModel(models.Model):
    name = models.CharField(max_length=255)
    phone_number = PhoneNumberField()
    fax_number = PhoneNumberField(blank=True)

 

Python port of Google's libphonenumber

The main object that the library deals with is a PhoneNumber object. You can create this from a string representing a phone number using the parse function, but you also need to specify the country that the phone number is being dialled from (unless the number is in E.164 format, which is globally unique).

>>> import phonenumbers
>>> x = phonenumbers.parse("+442083661177", None)
>>> print(x)
Country Code: 44 National Number: 2083661177 Leading Zero: False
>>> type(x)
<class 'phonenumbers.phonenumber.PhoneNumber'>
>>> y = phonenumbers.parse("020 8366 1177", "GB")
>>> print(y)
Country Code: 44 National Number: 2083661177 Leading Zero: False
>>> x == y
True
>>> z = phonenumbers.parse("00 1 650 253 2222", "GB")  # as dialled from GB, not a GB number
>>> print(z)
Country Code: 1 National Number: 6502532222 Leading Zero(s): False

 

Django-picklefield/

Django-picklefield - Python

159

A pickled object field for Django

To use, just define a field in your model:

>>> from picklefield.fields import PickledObjectField
... class SomeObject(models.Model):
...     args = PickledObjectField()

 

Django-searchable-select

Django-searchable-select - Python

100

A better and faster multiple selection widget with suggestions

Features

  • Filtering is performed on server side and thus significantly improves performance.
  • Uses Twitter Typeahead to provide suggestion completion.
  • Works great with ManyToMany fields that can be chosen from thousands of thousands of choices, e. g. User - City relations.

Add URL pattern required for the suggesting engine to your root urls.py.

# urls.py

urlpatterns = patterns(
    '',
    # ...
    url('^searchableselect/', include('searchableselect.urls')),
    # ...
)
Django-searchable-select
choice django django-searchable-select python widget

 

Django-uuidfield/

Django-uuidfield - Python

266

A UUIDField for Django

 

Django-versatileimagefield/

Django-versatileimagefield - Python

481

A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.