|PyPI latest| |GitHub Actions|
.. |PyPI latest| image:: https://img.shields.io/pypi/v/django-uidfield.svg?maxAge=120
:target: https://pypi.python.org/pypi/django-uidfield
.. |GitHub Actions| image:: https://github.com/ivelum/django-uidfield/actions/workflows/tests-and-codestyle.yaml/badge.svg
:target: https://github.com/ivelum/django-uidfield/actions/workflows/tests-and-codestyle.yaml
About
-----
Pretty UID fields for your Django models, with customizable prefixes and
controlled length. Tested against Python 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11,
3.12, 3.13 and Django 2.2, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1.
Usage
-----
See examples below. You can optionally inherit your models from `UIDModel`,
which gracefully handles IntegrityError on saving UIDs, making up to 3 attempts
with random UIDs. Integrity errors should be pretty rare if you use large enough
`max_length` on your fields, but you may still want to use it for extra safety:
.. code-block:: python
from django_uidfield.fields import UIDField
class YourModel(models.Model):
uid_field = UIDField(prefix='tmp_', max_length=20)
# the value will be like 'tmp_Akw81LmtPqS93dKb'
or:
.. code-block:: python
from django_uidfield.models import UIDModel
from django_uidfield.fields import UIDField
class YourModel(UIDModel):
uid_field = UIDField(prefix='tmp_', max_length=20)
Adding a UIDField to an existing model
--------------------------------------
You can populate the field with a data-migration:
.. code-block:: python
def populate_uid(apps, schema_editor):
User = apps.get_model("users", "User")
for user in User.objects.all():
user._meta.get_field("uid").populate(user, force_renew=True)
user.save()
class Migration(migrations.Migration):
operations = [migrations.RunPython(code=populate_uid)]
Note that the 3-attempt deduplication mechanism will not work, and you can get
an error if you have a lot of objects and a small max_length.
`Changelog <CHANGELOG.rst>`_
Raw data
{
"_id": null,
"home_page": "https://github.com/ivelum/django-uidfield/",
"name": "django-uidfield",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "django model field",
"author": "ivelum",
"author_email": "info@ivelum.com",
"download_url": "https://files.pythonhosted.org/packages/4f/dd/b79633e08ace69355986f0000075a82716a33125cc25d7101ff1e32c6035/django_uidfield-0.3.5.tar.gz",
"platform": null,
"description": "|PyPI latest| |GitHub Actions|\n\n.. |PyPI latest| image:: https://img.shields.io/pypi/v/django-uidfield.svg?maxAge=120\n :target: https://pypi.python.org/pypi/django-uidfield\n.. |GitHub Actions| image:: https://github.com/ivelum/django-uidfield/actions/workflows/tests-and-codestyle.yaml/badge.svg\n :target: https://github.com/ivelum/django-uidfield/actions/workflows/tests-and-codestyle.yaml\n\nAbout\n-----\n\nPretty UID fields for your Django models, with customizable prefixes and\ncontrolled length. Tested against Python 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11,\n3.12, 3.13 and Django 2.2, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1.\n\n\nUsage\n-----\n\nSee examples below. You can optionally inherit your models from `UIDModel`,\nwhich gracefully handles IntegrityError on saving UIDs, making up to 3 attempts\nwith random UIDs. Integrity errors should be pretty rare if you use large enough\n`max_length` on your fields, but you may still want to use it for extra safety:\n\n.. code-block:: python\n\n from django_uidfield.fields import UIDField\n\n class YourModel(models.Model):\n uid_field = UIDField(prefix='tmp_', max_length=20)\n\n # the value will be like 'tmp_Akw81LmtPqS93dKb'\n\nor:\n\n.. code-block:: python\n\n from django_uidfield.models import UIDModel\n from django_uidfield.fields import UIDField\n\n\n class YourModel(UIDModel):\n uid_field = UIDField(prefix='tmp_', max_length=20)\n\n\nAdding a UIDField to an existing model\n--------------------------------------\n\nYou can populate the field with a data-migration:\n\n.. code-block:: python\n\n def populate_uid(apps, schema_editor):\n User = apps.get_model(\"users\", \"User\")\n\n for user in User.objects.all():\n user._meta.get_field(\"uid\").populate(user, force_renew=True)\n user.save()\n\n\n class Migration(migrations.Migration):\n operations = [migrations.RunPython(code=populate_uid)]\n\nNote that the 3-attempt deduplication mechanism will not work, and you can get\nan error if you have a lot of objects and a small max_length.\n\n\n`Changelog <CHANGELOG.rst>`_\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "django-uidfield is a library which includes class UIDField for models.",
"version": "0.3.5",
"project_urls": {
"Homepage": "https://github.com/ivelum/django-uidfield/"
},
"split_keywords": [
"django",
"model",
"field"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "33f1c17db33ce7677241222b02389922142d83bbbc620b46e6dcf7a7c97f49f1",
"md5": "e23426cd146fb65f8927ed84382ff7a7",
"sha256": "94cbf5adaa3a0e9c7b5e32178e1fc69bcc51d4050c2b51c9f1577850f34bb584"
},
"downloads": -1,
"filename": "django_uidfield-0.3.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e23426cd146fb65f8927ed84382ff7a7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6550,
"upload_time": "2024-12-17T07:39:08",
"upload_time_iso_8601": "2024-12-17T07:39:08.894701Z",
"url": "https://files.pythonhosted.org/packages/33/f1/c17db33ce7677241222b02389922142d83bbbc620b46e6dcf7a7c97f49f1/django_uidfield-0.3.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4fddb79633e08ace69355986f0000075a82716a33125cc25d7101ff1e32c6035",
"md5": "247156e8d9f60e035e9497f4bdb1dc80",
"sha256": "ce180adc4b70ad0049b3668d025ee69b2b5374f1484fde7e17f8332ab7014a7f"
},
"downloads": -1,
"filename": "django_uidfield-0.3.5.tar.gz",
"has_sig": false,
"md5_digest": "247156e8d9f60e035e9497f4bdb1dc80",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5885,
"upload_time": "2024-12-17T07:39:11",
"upload_time_iso_8601": "2024-12-17T07:39:11.661282Z",
"url": "https://files.pythonhosted.org/packages/4f/dd/b79633e08ace69355986f0000075a82716a33125cc25d7101ff1e32c6035/django_uidfield-0.3.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-17 07:39:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ivelum",
"github_project": "django-uidfield",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-uidfield"
}