django-random-id


Namedjango-random-id JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryA model base class which provides custom designed random integer primary keys to you Django models.
upload_time2023-08-31 19:58:05
maintainer
docs_urlNone
authorSerdar Ilarslan
requires_python
licenseMIT
keywords django orm primary-key
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Random ID

A model base class which provides custom designed random integer primary keys
to you Django models.

## Installation

Run the following to install:
```python
pip install django_random_id
```

## Usage

The original way of creating and assigning primary keys in Django models

```python
from django.db import models

class CustomUser(models.Model):
    name = models.CharField(max_length=30, blank=False)

steve = CustomUser.objects.create(name="Steve")
bill = CustomUser.objects.create(name="Bill")
print(steve.id) 
# >>> '1'
print(bill.id) 
# >>> '2'
```

The primary keys are auto-incremental integers.

Now, let's see how `RandomIDModel` helps you:

```python
from django.db import models
from django_random_id import RandomIDModel

class CustomUser(RandomIDModel):
    name = models.CharField(max_length=30, blank=False)

steve = CustomUser.objects.create(name="Steve")
bill = CustomUser.objects.create(name="Bill")
print(steve.id) 
# >>> '425291518806427'
print(bill.id) 
# >>> '607559381880556'
```

The Random primary ID is guaranteed to be unique.

By default the ID will be 16 digits long, but you can change this in
settings.py with the `RANDOM_ID_MODEL_LENGTH` setting.

You can also use `RandomAlphaNumIDModel` base model to generate string 
alphanumerical primary keys.

## Testing - In Progress

To install django_random_id, along with the tools you need to develop and 
run the tests, run the following in your virtual environment:

```bash
$ pip install -e .[dev]
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "django-random-id",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django orm primary-key",
    "author": "Serdar Ilarslan",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/cc/4b/8c6354a878e0918881664d1316d0fd832254b8c3d520d7387338a59b3899/django_random_id-0.1.0.tar.gz",
    "platform": null,
    "description": "# Django Random ID\r\n\r\nA model base class which provides custom designed random integer primary keys\r\nto you Django models.\r\n\r\n## Installation\r\n\r\nRun the following to install:\r\n```python\r\npip install django_random_id\r\n```\r\n\r\n## Usage\r\n\r\nThe original way of creating and assigning primary keys in Django models\r\n\r\n```python\r\nfrom django.db import models\r\n\r\nclass CustomUser(models.Model):\r\n    name = models.CharField(max_length=30, blank=False)\r\n\r\nsteve = CustomUser.objects.create(name=\"Steve\")\r\nbill = CustomUser.objects.create(name=\"Bill\")\r\nprint(steve.id) \r\n# >>> '1'\r\nprint(bill.id) \r\n# >>> '2'\r\n```\r\n\r\nThe primary keys are auto-incremental integers.\r\n\r\nNow, let's see how `RandomIDModel` helps you:\r\n\r\n```python\r\nfrom django.db import models\r\nfrom django_random_id import RandomIDModel\r\n\r\nclass CustomUser(RandomIDModel):\r\n    name = models.CharField(max_length=30, blank=False)\r\n\r\nsteve = CustomUser.objects.create(name=\"Steve\")\r\nbill = CustomUser.objects.create(name=\"Bill\")\r\nprint(steve.id) \r\n# >>> '425291518806427'\r\nprint(bill.id) \r\n# >>> '607559381880556'\r\n```\r\n\r\nThe Random primary ID is guaranteed to be unique.\r\n\r\nBy default the ID will be 16 digits long, but you can change this in\r\nsettings.py with the `RANDOM_ID_MODEL_LENGTH` setting.\r\n\r\nYou can also use `RandomAlphaNumIDModel` base model to generate string \r\nalphanumerical primary keys.\r\n\r\n## Testing - In Progress\r\n\r\nTo install django_random_id, along with the tools you need to develop and \r\nrun the tests, run the following in your virtual environment:\r\n\r\n```bash\r\n$ pip install -e .[dev]\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A model base class which provides custom designed random integer primary keys to you Django models.",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [
        "django",
        "orm",
        "primary-key"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90cf7bad67c89b9dc8b0d9edcedb82e7552885b143d570d26e892a02ff199081",
                "md5": "f411dac4fb881a455d7af89484a541ab",
                "sha256": "ef026c5cbee06cb56c1f250434d3d9162d55e1340b4167e5bc0da7f42b65a10e"
            },
            "downloads": -1,
            "filename": "django_random_id-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f411dac4fb881a455d7af89484a541ab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3650,
            "upload_time": "2023-08-31T19:58:03",
            "upload_time_iso_8601": "2023-08-31T19:58:03.500558Z",
            "url": "https://files.pythonhosted.org/packages/90/cf/7bad67c89b9dc8b0d9edcedb82e7552885b143d570d26e892a02ff199081/django_random_id-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc4b8c6354a878e0918881664d1316d0fd832254b8c3d520d7387338a59b3899",
                "md5": "5c60a4342da688f13b2e676c2d15699f",
                "sha256": "53867bd51b57c93e024a90b525393a82ca72dda85aee445c5a5e08663c6c3f61"
            },
            "downloads": -1,
            "filename": "django_random_id-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5c60a4342da688f13b2e676c2d15699f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3363,
            "upload_time": "2023-08-31T19:58:05",
            "upload_time_iso_8601": "2023-08-31T19:58:05.315203Z",
            "url": "https://files.pythonhosted.org/packages/cc/4b/8c6354a878e0918881664d1316d0fd832254b8c3d520d7387338a59b3899/django_random_id-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-31 19:58:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "django-random-id"
}
        
Elapsed time: 0.14691s