Skip to main content

Django-objectid

Django-objectid用于Django框架在分布式环境中高效生成不重复ID值。

依赖

  • django >= 2.2.0

安装

  • pip安装
pip install django-objectid
  • 源码安装
python setup.py install

发布包

# 打包
python setup.py bdist_wheel
# 上传
twine upload -u __token__ ./dist/*

使用

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中的时间戳。
  • 多数据中心布署时,settings中增加配置 DCID,数据中心ID,默认为0。

Metadata

Release files for django-objectid 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for django-objectid 1.0.11
File Interpreter ABI Platform
django_objectid-1.0.11-py3-none-any.whl Python 3 none any Details

Release files / django_objectid-1.0.11-py3-none-any.whl

Download URL django_objectid-1.0.11-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b105f64babed8776273780886e9728618a4f640981088289708df49288564f9
BLAKE2b-256 checksum
How to use checksums
296c8c2c0e56d764bbf12e9a85c2e790e679137cd45a149e9f90a2e39db88dfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.0.11 This release

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page