django-nativeshortuuidfield


Namedjango-nativeshortuuidfield JSON
Version 1.4.6 PyPI version JSON
download
home_pagehttps://github.com/foundertherapy/django-nativeshortuuidfield
SummaryA decoder/encoder Field for uuid
upload_time2024-01-16 18:04:50
maintainer
docs_urlNone
authorLaith Abu Zainih
requires_python>=3
licenseMIT
keywords shortuuid uuid nativeshortuuid
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-nativeshortuuidfield

[![Tests](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/tests.yml/badge.svg)](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/tests.yml)
[![Linters](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/linters.yml/badge.svg)](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/linters.yml)

Provides a NativeShortUUIDField for your Django models which uses the base-57 "Short UUID" package at https://github.com/stochastic-technologies/shortuuid/ to be used in Python
and store it as full UUID in database.

## Installation

Install it with pip (or easy_install):
```bash
$ pip install django-nativeshortuuidfield
```

## Usage

First you'll need to add a NativeShortUUIDField to your class:
```python
from native_shortuuid import NativeShortUUIDField

class MyModel(models.Model):
    uuid = NativeShortUUIDField(unique=True, default=uuid.uuid4)
```

If you want to add the ability to search by shortuuid in `ModelAdmin` you need to inherit `NativeUUIDSearchMixin`
```python
from native_shortuuid.admin import NativeUUIDSearchMixin

@admin.register(models.MyModel)
class MyModelAdmin(NativeUUIDSearchMixin, admin.ModelAdmin):
    search_fields = ('uuid', )
``` 

If you want to have to ability to write your own uuid search fields list
```python
from native_shortuuid.admin import NativeUUIDSearchMixin

@admin.register(models.MyModel)
class MyModelAdmin(NativeUUIDSearchMixin, admin.ModelAdmin):
    admin_auto_extract_uuid_search_fields = False
    search_fields = ('name', )
    search_uuid_fields = ['uuid', 'foreign_model__uuid']
``` 


Enjoy!

## Settings
* `ADMIN_AUTO_EXTRACT_UUID_SEARCH_FIELDS`: default `True`
    + This setting is to autofill `search_uuid_fields` in the ModelAdmins that inherits `NativeUUIDSearchMixin` 
    with all shortuuid fields that are in the `search_fields` array.
    if you turned it off, you'll need to define `search_uuid_fields` on you ModelAdmin in order to search on shortuuid fields
    
## Notes

* NativeShortUUIDField is a subclass of django.db.models.UUIDField

* You can pass usual Django UUIDField parameters on init, although some of them are added/overwritten:
    + blank=True, editable=False (set auto=False to remove these fields enforcement)

### Contribution Notes

#### Pull Request
* Increase the version number in the `setup.py` to the new version that the new pull request represents.

#### Publishing the Package
After the pull request gets merged into the master branch a new release should be created

* Create a new tag with the same version number you updated the `setup.py` with:
    ```bash
    $ git checkout master
    $ git tag -a 2.1.0 -m 'fix importing order'
    $ git push origin 2.1.0
    ```

* Go to GitHub's releases section and create a new release:
    + Chose the tag version that you just created
    + Fill the release title with the same version number
    + Add a description of the release and publish it

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/foundertherapy/django-nativeshortuuidfield",
    "name": "django-nativeshortuuidfield",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "shortuuid uuid nativeshortuuid",
    "author": "Laith Abu Zainih",
    "author_email": "systems@foundertherapy.co",
    "download_url": "https://files.pythonhosted.org/packages/ed/7c/b6397aa4b23c1b4e409bd76a5073f54bff2fc2146b0127c77d5213f61aab/django-nativeshortuuidfield-1.4.6.tar.gz",
    "platform": null,
    "description": "# django-nativeshortuuidfield\n\n[![Tests](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/tests.yml/badge.svg)](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/tests.yml)\n[![Linters](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/linters.yml/badge.svg)](https://github.com/foundertherapy/django-nativeshortuuidfield/actions/workflows/linters.yml)\n\nProvides a NativeShortUUIDField for your Django models which uses the base-57 \"Short UUID\" package at https://github.com/stochastic-technologies/shortuuid/ to be used in Python\nand store it as full UUID in database.\n\n## Installation\n\nInstall it with pip (or easy_install):\n```bash\n$ pip install django-nativeshortuuidfield\n```\n\n## Usage\n\nFirst you'll need to add a NativeShortUUIDField to your class:\n```python\nfrom native_shortuuid import NativeShortUUIDField\n\nclass MyModel(models.Model):\n    uuid = NativeShortUUIDField(unique=True, default=uuid.uuid4)\n```\n\nIf you want to add the ability to search by shortuuid in `ModelAdmin` you need to inherit `NativeUUIDSearchMixin`\n```python\nfrom native_shortuuid.admin import NativeUUIDSearchMixin\n\n@admin.register(models.MyModel)\nclass MyModelAdmin(NativeUUIDSearchMixin, admin.ModelAdmin):\n    search_fields = ('uuid', )\n``` \n\nIf you want to have to ability to write your own uuid search fields list\n```python\nfrom native_shortuuid.admin import NativeUUIDSearchMixin\n\n@admin.register(models.MyModel)\nclass MyModelAdmin(NativeUUIDSearchMixin, admin.ModelAdmin):\n    admin_auto_extract_uuid_search_fields = False\n    search_fields = ('name', )\n    search_uuid_fields = ['uuid', 'foreign_model__uuid']\n``` \n\n\nEnjoy!\n\n## Settings\n* `ADMIN_AUTO_EXTRACT_UUID_SEARCH_FIELDS`: default `True`\n    + This setting is to autofill `search_uuid_fields` in the ModelAdmins that inherits `NativeUUIDSearchMixin` \n    with all shortuuid fields that are in the `search_fields` array.\n    if you turned it off, you'll need to define `search_uuid_fields` on you ModelAdmin in order to search on shortuuid fields\n    \n## Notes\n\n* NativeShortUUIDField is a subclass of django.db.models.UUIDField\n\n* You can pass usual Django UUIDField parameters on init, although some of them are added/overwritten:\n    + blank=True, editable=False (set auto=False to remove these fields enforcement)\n\n### Contribution Notes\n\n#### Pull Request\n* Increase the version number in the `setup.py` to the new version that the new pull request represents.\n\n#### Publishing the Package\nAfter the pull request gets merged into the master branch a new release should be created\n\n* Create a new tag with the same version number you updated the `setup.py` with:\n    ```bash\n    $ git checkout master\n    $ git tag -a 2.1.0 -m 'fix importing order'\n    $ git push origin 2.1.0\n    ```\n\n* Go to GitHub's releases section and create a new release:\n    + Chose the tag version that you just created\n    + Fill the release title with the same version number\n    + Add a description of the release and publish it\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A decoder/encoder Field for uuid",
    "version": "1.4.6",
    "project_urls": {
        "Homepage": "https://github.com/foundertherapy/django-nativeshortuuidfield"
    },
    "split_keywords": [
        "shortuuid",
        "uuid",
        "nativeshortuuid"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82bb0233891129e3806484b229563811bc90fdb10cf64bb71a06ff93c784cf95",
                "md5": "0164b058910dcd778b9c28c339d2eac3",
                "sha256": "1a71a2363fb99bd21a8a852807a66f6f303ce292301a75f775226d825b132d42"
            },
            "downloads": -1,
            "filename": "django_nativeshortuuidfield-1.4.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0164b058910dcd778b9c28c339d2eac3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 11296,
            "upload_time": "2024-01-16T18:04:49",
            "upload_time_iso_8601": "2024-01-16T18:04:49.705798Z",
            "url": "https://files.pythonhosted.org/packages/82/bb/0233891129e3806484b229563811bc90fdb10cf64bb71a06ff93c784cf95/django_nativeshortuuidfield-1.4.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed7cb6397aa4b23c1b4e409bd76a5073f54bff2fc2146b0127c77d5213f61aab",
                "md5": "b43c6f003591c793d877a9a02a2153a3",
                "sha256": "9eab4888bb590faf1eb6359958abd800905ef10e01e5f0bcab184d63fe0fb8d2"
            },
            "downloads": -1,
            "filename": "django-nativeshortuuidfield-1.4.6.tar.gz",
            "has_sig": false,
            "md5_digest": "b43c6f003591c793d877a9a02a2153a3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 9812,
            "upload_time": "2024-01-16T18:04:50",
            "upload_time_iso_8601": "2024-01-16T18:04:50.880836Z",
            "url": "https://files.pythonhosted.org/packages/ed/7c/b6397aa4b23c1b4e409bd76a5073f54bff2fc2146b0127c77d5213f61aab/django-nativeshortuuidfield-1.4.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-16 18:04:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "foundertherapy",
    "github_project": "django-nativeshortuuidfield",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-nativeshortuuidfield"
}
        
Elapsed time: 0.16687s