django-dynamic-filenames


Namedjango-dynamic-filenames JSON
Version 1.3.2 PyPI version JSON
download
home_pagehttps://github.com/codingjoe/django-dynamic-filenames
SummaryWrite advanced filename patterns using the Format String Syntax.
upload_time2023-06-22 06:39:00
maintainer
docs_urlNone
authorJohannes Maron
requires_python
licenseMIT License
keywords django django-storages file
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========================
Django Dynamic Filenames
========================

Write advanced filename patterns using the `Format String Syntax`__.

__ https://docs.python.org/3/library/string.html#format-string-syntax

Getting Started
---------------

Installation
~~~~~~~~~~~~

.. code-block:: bash

    pip install django-dynamic-filenames

Samples
~~~~~~~

Basic example:

.. code-block:: python

    from django.db import models
    from dynamic_filenames import FilePattern

    upload_to_pattern = FilePattern(
        filename_pattern='{app_label:.25}/{model_name:.30}/{uuid:base32}{ext}'
    )

    class FileModel(models.Model):
        my_file = models.FileField(upload_to=upload_to_pattern)


Auto slug example:


Features
--------

Field names
~~~~~~~~~~~

``ext``
    File extension including the dot.

``name``
    Filename excluding the folders.

``model_name``
    Name of the Django model.

``app_label``
    App label of the Django model.

``instance``
    Instance of the model before it has been saved. You may not have a primary
    key at this point.

``uuid``
    UUID version 4 that supports multiple type specifiers. The UUID will be
    the same should you use it twice in the same string, but different on each
    invocation of the ``upload_to`` callable.

    The type specifiers allow you to format the UUID in different ways, e.g.
    ``{uuid:x}`` will give you a with a hexadecimal UUID.

    The supported type specifiers are:

    ``s``
        String representation of a UUID including dashes.

    ``i``
        Integer representation of a UUID. Like to ``UUID.int``.

    ``x``
        Hexadecimal (Base16) representation of a UUID. Like to ``UUID.hex``.

    ``X``
        Upper case hexadecimal representation of a UUID. Like to
        ``UUID.hex``.

    ``base32``
        Base32 representation of a UUID without padding.

    ``base64``
        Base64 representation of a UUID without padding.

        .. warning:: Not all file systems support Base64 file names.

    All type specifiers also support precisions to cut the string,
    e.g. ``{{uuid:.2base32}}`` would only return the first 2 characters of a
    Base32 encoded UUID.

Type specifiers
~~~~~~~~~~~~~~~

You can also use a special slug type specifier, that slugifies strings.

Example:

.. code-block:: python

    from django.db import models
    from dynamic_filenames import FilePattern

    upload_to_pattern = FilePattern(
        filename_pattern='{app_label:.25}/{model_name:.30}/{instance.title:.40slug}{ext}'
    )

    class FileModel(models.Model):
        title = models.CharField(max_length=100)
        my_file = models.FileField(upload_to=upload_to_pattern)

Slug type specifiers also support precisions to cut the string. In the example
above the slug of the instance title will be cut at 40 characters.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/codingjoe/django-dynamic-filenames",
    "name": "django-dynamic-filenames",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django,django-storages,file",
    "author": "Johannes Maron",
    "author_email": "johannes@maron.family",
    "download_url": "https://files.pythonhosted.org/packages/66/21/983489a524a506e360336fd0d1846edd404b10ac3b89192009256c569563/django-dynamic-filenames-1.3.2.tar.gz",
    "platform": null,
    "description": "========================\nDjango Dynamic Filenames\n========================\n\nWrite advanced filename patterns using the `Format String Syntax`__.\n\n__ https://docs.python.org/3/library/string.html#format-string-syntax\n\nGetting Started\n---------------\n\nInstallation\n~~~~~~~~~~~~\n\n.. code-block:: bash\n\n    pip install django-dynamic-filenames\n\nSamples\n~~~~~~~\n\nBasic example:\n\n.. code-block:: python\n\n    from django.db import models\n    from dynamic_filenames import FilePattern\n\n    upload_to_pattern = FilePattern(\n        filename_pattern='{app_label:.25}/{model_name:.30}/{uuid:base32}{ext}'\n    )\n\n    class FileModel(models.Model):\n        my_file = models.FileField(upload_to=upload_to_pattern)\n\n\nAuto slug example:\n\n\nFeatures\n--------\n\nField names\n~~~~~~~~~~~\n\n``ext``\n    File extension including the dot.\n\n``name``\n    Filename excluding the folders.\n\n``model_name``\n    Name of the Django model.\n\n``app_label``\n    App label of the Django model.\n\n``instance``\n    Instance of the model before it has been saved. You may not have a primary\n    key at this point.\n\n``uuid``\n    UUID version 4 that supports multiple type specifiers. The UUID will be\n    the same should you use it twice in the same string, but different on each\n    invocation of the ``upload_to`` callable.\n\n    The type specifiers allow you to format the UUID in different ways, e.g.\n    ``{uuid:x}`` will give you a with a hexadecimal UUID.\n\n    The supported type specifiers are:\n\n    ``s``\n        String representation of a UUID including dashes.\n\n    ``i``\n        Integer representation of a UUID. Like to ``UUID.int``.\n\n    ``x``\n        Hexadecimal (Base16) representation of a UUID. Like to ``UUID.hex``.\n\n    ``X``\n        Upper case hexadecimal representation of a UUID. Like to\n        ``UUID.hex``.\n\n    ``base32``\n        Base32 representation of a UUID without padding.\n\n    ``base64``\n        Base64 representation of a UUID without padding.\n\n        .. warning:: Not all file systems support Base64 file names.\n\n    All type specifiers also support precisions to cut the string,\n    e.g. ``{{uuid:.2base32}}`` would only return the first 2 characters of a\n    Base32 encoded UUID.\n\nType specifiers\n~~~~~~~~~~~~~~~\n\nYou can also use a special slug type specifier, that slugifies strings.\n\nExample:\n\n.. code-block:: python\n\n    from django.db import models\n    from dynamic_filenames import FilePattern\n\n    upload_to_pattern = FilePattern(\n        filename_pattern='{app_label:.25}/{model_name:.30}/{instance.title:.40slug}{ext}'\n    )\n\n    class FileModel(models.Model):\n        title = models.CharField(max_length=100)\n        my_file = models.FileField(upload_to=upload_to_pattern)\n\nSlug type specifiers also support precisions to cut the string. In the example\nabove the slug of the instance title will be cut at 40 characters.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Write advanced filename patterns using the Format String Syntax.",
    "version": "1.3.2",
    "project_urls": {
        "Homepage": "https://github.com/codingjoe/django-dynamic-filenames"
    },
    "split_keywords": [
        "django",
        "django-storages",
        "file"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "59de9904ac45bd2b3a62a6bc4853bf8896c1383c07c248676538b9e65ab6a4d9",
                "md5": "7718bd92cfa662d6bc03862baa8b087f",
                "sha256": "a78cb1a7b3642dc57c14ef8cc345894d988a4453ca6125292cefd3c328450417"
            },
            "downloads": -1,
            "filename": "django_dynamic_filenames-1.3.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7718bd92cfa662d6bc03862baa8b087f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4888,
            "upload_time": "2023-06-22T06:38:58",
            "upload_time_iso_8601": "2023-06-22T06:38:58.654256Z",
            "url": "https://files.pythonhosted.org/packages/59/de/9904ac45bd2b3a62a6bc4853bf8896c1383c07c248676538b9e65ab6a4d9/django_dynamic_filenames-1.3.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6621983489a524a506e360336fd0d1846edd404b10ac3b89192009256c569563",
                "md5": "76a630cbba67a2392a29d99398499c9d",
                "sha256": "07c2f047fbb76c02f153305d53fdd95890cdbd5690072c7109a5638d4b456989"
            },
            "downloads": -1,
            "filename": "django-dynamic-filenames-1.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "76a630cbba67a2392a29d99398499c9d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9979,
            "upload_time": "2023-06-22T06:39:00",
            "upload_time_iso_8601": "2023-06-22T06:39:00.073808Z",
            "url": "https://files.pythonhosted.org/packages/66/21/983489a524a506e360336fd0d1846edd404b10ac3b89192009256c569563/django-dynamic-filenames-1.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-22 06:39:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "codingjoe",
    "github_project": "django-dynamic-filenames",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-dynamic-filenames"
}
        
Elapsed time: 0.08373s