django objectid
Project description
Django-objectid
Django-objectid用于Django框架在分布式环境中高效生成不重复ID值。
依赖
- django >= 2.2.0
安装
- pip安装
pip install django-objectid
- 源码安装
python setup.py install
使用
Django-objectid包括两个类,ObjectID
,ObjectidModel
。
class objectid.ObjectID(id=None)
生成、解析objectid。
参数id是一个长度为24的字符,如果是None
则生成新的ObjectID实例,如果提供一个有效ID则解析这个ID为ObjectID实例。ObjectID实例有如下属性:
timestamp
,ID中的时间戳,也就是ID创建的时间。host
,ID中的主机名,是实际主机名经过哈希处理后的值。pid
,进程ID,可能与实际值不一致。count
,同一进程一秒内生成的ID序号。
from objectid import ObjectID, create_objectid
# 创建ID对象
id = ObjectID()
# 获得id字符串
idstr = str(id)
# 直接创建id字符串
idstr = create_objectid()
# 解析id字符串
id = ObjectID('5fb1ee9af1d79721f0000015')
class objectid.ObjectidModel()
ObjectidModel
是一个抽象类,不能单独使用,作为定义django模型类的基类。实例对象有如下属性和方法:
- get_id_datetime(),返回id中的时间戳。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-objectid-1.0.0.tar.gz
(2.9 kB
view details)
Built Distribution
File details
Details for the file django-objectid-1.0.0.tar.gz
.
File metadata
- Download URL: django-objectid-1.0.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b6579583e2f0c41d4405d6249dbcf93269c9fb3105c16bfcd91d755d7f90697 |
|
MD5 | 7ae2bb8cb8ea182f6400c6e32e49ff4a |
|
BLAKE2b-256 | 12e1f6ac78350796b49976cfbc3fb358e86b2ec6e7de60b9c5da09e2e58b5498 |
File details
Details for the file django_objectid-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_objectid-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85dcac60ca8581938a0760960d5a4f69761cbbd3b9df3c7799c032641d36253c |
|
MD5 | 96b073905baf96b5f2a8c9e941f6668f |
|
BLAKE2b-256 | 84d1b700f0f1c0fb643dce6606eb2da2217955ff16736221d609f986d65dc7eb |