Name | django-nanoid-field JSON |
Version |
0.1.2
JSON |
| download |
home_page | |
Summary | Next generation NanoID in Django Model IDs |
upload_time | 2023-10-30 14:33:05 |
maintainer | |
docs_url | None |
author | |
requires_python | |
license | MIT |
keywords |
django
nanoid
django-field
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Django NanoID Field
NanoID is an alternative to UUID, CUID for generating random IDs. This package
provides a field to use in models.
## Installation
Install it from PyPI:
```sh
pip install django-nanoid-field
```
## Usage
First, add it to your applications (Not Required)
```python
INSTALLED_APPS = [
# ...
'nanoid_field',
# ...
]
```
You can now use it in your models like:
```python
from django.db import models
from nanoid_field import NanoidField
class Profile(models.Model):
hash = NanoidField(max_length=10, alphabet='0123456789abcdefghijklmnopqrstuvwxyz)
```
## NanoidField
This model field is based on `CharField`. All of it's parameters can be used.
Additionally following fields affects outcome of NanoID:
### `max_length` Parameter (Optional)
Determines size of the generated ID as well as length of the field in Database.
#### **DEFAULT:**
```
21
```
### `alphabet` Parameter (Optional)
This optional parameter helps you to determine which characters will be used to
build up.
#### **DEFAULT:**
```
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-
```
## Using NanoidField as `primary_key`
Currently Django Auto Field feature does not allow using fields other than
Integer based fields. Until this ability changes you cannot use this as AutoField.
To use NanoID as default `primary_key` you need to explicitly define it in your
model:
```python
from django.db import models
class SomeModel(models.Model):
id = NanoidField()
# ...
```
## Changing defaults
`django-nanoid-field` also provides two settings to change defaults of `alphabet`
and `max_length`. You can change those by adding them to your `settings.py` file
```python
# settings.py file
NANOID_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-"
NANOID_SIZE = 21
```
Raw data
{
"_id": null,
"home_page": "",
"name": "django-nanoid-field",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django,nanoid,django-field",
"author": "",
"author_email": "Gokhan Ozturk <me@gokhan.org.tr>",
"download_url": "https://files.pythonhosted.org/packages/11/26/7803604bc35ae0bb5e29a8b50356690f92c7e61fd949988586031de443e5/django-nanoid-field-0.1.2.tar.gz",
"platform": null,
"description": "# Django NanoID Field\n\nNanoID is an alternative to UUID, CUID for generating random IDs. This package\nprovides a field to use in models.\n\n\n## Installation\n\nInstall it from PyPI:\n\n```sh\npip install django-nanoid-field\n```\n\n\n## Usage\n\nFirst, add it to your applications (Not Required)\n\n```python\nINSTALLED_APPS = [\n # ...\n 'nanoid_field',\n # ...\n]\n```\n\nYou can now use it in your models like:\n\n```python\nfrom django.db import models\nfrom nanoid_field import NanoidField\n\nclass Profile(models.Model):\n hash = NanoidField(max_length=10, alphabet='0123456789abcdefghijklmnopqrstuvwxyz)\n```\n\n\n## NanoidField\n\nThis model field is based on `CharField`. All of it's parameters can be used.\n\nAdditionally following fields affects outcome of NanoID:\n\n\n### `max_length` Parameter (Optional)\nDetermines size of the generated ID as well as length of the field in Database.\n\n#### **DEFAULT:**\n```\n21\n```\n\n\n### `alphabet` Parameter (Optional)\nThis optional parameter helps you to determine which characters will be used to\nbuild up.\n\n#### **DEFAULT:**\n```\n0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-\n```\n\n\n## Using NanoidField as `primary_key`\n\nCurrently Django Auto Field feature does not allow using fields other than\nInteger based fields. Until this ability changes you cannot use this as AutoField.\n\nTo use NanoID as default `primary_key` you need to explicitly define it in your\nmodel:\n\n```python\nfrom django.db import models\n\n\nclass SomeModel(models.Model):\n id = NanoidField()\n # ...\n```\n\n## Changing defaults\n`django-nanoid-field` also provides two settings to change defaults of `alphabet`\nand `max_length`. You can change those by adding them to your `settings.py` file\n\n```python\n# settings.py file\n\nNANOID_ALPHABET = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-\"\nNANOID_SIZE = 21\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Next generation NanoID in Django Model IDs",
"version": "0.1.2",
"project_urls": {
"Documentation": "https://github.com/goztrk/django-nanoid-field",
"Homepage": "https://github.com/goztrk/django-nanoid-field",
"Repository": "https://github.com/goztrk/django-nanoid-field.git"
},
"split_keywords": [
"django",
"nanoid",
"django-field"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d878d6a614bd28c678e1cffcb09cc3a3bad83e5cc65492df425e66e8da041222",
"md5": "90872a50e5a720702ef9321a06def843",
"sha256": "b960dd61f6a562a2329a12a05cc12c500a007ec689e8e50f4696033d9aec75aa"
},
"downloads": -1,
"filename": "django_nanoid_field-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "90872a50e5a720702ef9321a06def843",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3860,
"upload_time": "2023-10-30T14:33:04",
"upload_time_iso_8601": "2023-10-30T14:33:04.231468Z",
"url": "https://files.pythonhosted.org/packages/d8/78/d6a614bd28c678e1cffcb09cc3a3bad83e5cc65492df425e66e8da041222/django_nanoid_field-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "11267803604bc35ae0bb5e29a8b50356690f92c7e61fd949988586031de443e5",
"md5": "641136ab0f8d401b8154f2bcca333007",
"sha256": "547258777ea47ff681cb687dca277cb8859bd4fef00c357e4b0be1f81f99a516"
},
"downloads": -1,
"filename": "django-nanoid-field-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "641136ab0f8d401b8154f2bcca333007",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3356,
"upload_time": "2023-10-30T14:33:05",
"upload_time_iso_8601": "2023-10-30T14:33:05.852869Z",
"url": "https://files.pythonhosted.org/packages/11/26/7803604bc35ae0bb5e29a8b50356690f92c7e61fd949988586031de443e5/django-nanoid-field-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-30 14:33:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "goztrk",
"github_project": "django-nanoid-field",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-nanoid-field"
}