This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Installation

  1. pip install django-modeltools

Included Tools

Enum

The Enum class lets you quickly define enumeration types for model field values. The constructor accepts kwargs where the key is the name of the “constant” and the value is a two-tuple containing the value of the constant (which will be stored in the database) and a label.

Usage

In models.py:

from modeltools import Enum

class MyModel(models.Model):

    Color = Enum(
        RED=('r', 'Red'),
        GREEN=('g', 'Green'),
        BLUE=('b', 'Blue'),
    )

    color = models.CharField(max_length=1, choices=Color.choices())

Elsewhere:

m = MyModel.objects.filter(color=MyModel.Color.RED)

format_filename

The format_filename function provides an easy way to name user media (uploaded files) based on properties of the model that stores them.

Usage

In models.py:

from modeltools import format_filename as _ff

class Person(models.Model):
        first_name = models.CharField(max_length=50)
        last_name = models.CharField(max_length=50)
        middle_name = models.CharField(max_length=50)
        avatar = models.ImageField(upload_to=_ff('avatars/{last_name}_{first_name}'))

In the above example, {first_name} and {last_name} will be replaced with the corresponding values from the Person instance. The uploaded file will automatically retain its original extension.

upload_to=_ff('avatars/{last_name}_{first_name}/{__filename}.thumbnail{__ext}')

{__filename} and {__ext} allows access to the name and extension the file was uploaded with.

By default, the properties used in the formatting pattern will be converted to lowercase, stripped of non-word characters, and have their spaces replaced with underscores. (This behavior can be changed by providing extra arguments to the format_filename function.) The rest of the formatting string will be unaffected.

Release History

Release History

1.0.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-modeltools-1.0.1.tar.gz (5.1 kB) Copy SHA256 Checksum SHA256 Source Nov 13, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting