------------
1. `pip install -e git+git://github.com/hzdg/django-modeltools.git#egg=django-modeltools`
Included Tools
-----
### Enum
The `Enum` class lets you quickly define enumeration types for model field
values. It uses [Pep 435][1]-style enums, but has some extra model-specific
functionality (like the ability to easily add custom labels).
[1]: http://www.python.org/dev/peps/pep-0435/
#### Usage
In models.py:
from modeltools import Enum, EnumField
class MyModel(models.Model):
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
color = models.EnumField(Color)
Elsewhere:
m = MyModel.objects.filter(color=MyModel.Color.RED)
#### Custom Labels
By default, labels are title-cased versions of your enum member names (e.g.
"Red" for `Color.RED`). You can customize this with an inner `Labels` class.
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class Labels:
RED = 'El color del diablo'
#### Ordering
Members aren't automatically ordered in Python 2.X enums. You have to do it
yourself using an `__order__` attribute.
class Color(Enum):
__order__ = 'RED GREEN BLUE'
RED = 'r'
GREEN = 'g'
BLUE = 'b'
### 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.
Metadata
Release files for django-modeltools 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-modeltools-1.0.0.tar.gz | 6.1 kB | Without provenance | Details for django-modeltools-1.0.0.tar.gz |
Release files / django-modeltools-1.0.0.tar.gz
| Download URL | django-modeltools-1.0.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1b37b509367b4487dd7f35a798021533f67eb2ec97c1f763099c5bb01af8180
|
|
BLAKE2b-256 checksum How to use checksums |
9ef6e70882ebb9ca24378982615b745464d80a8995562b343e099f8fc10a7ce5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-modeltools 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.