Models with auto input fields for Django
Project description
DjangoAutoModels
自動入力フィールドを備えたDjango用のAbstract Model群です。
適応させたいモデルに継承させて使用します。
導入
-
ライブラリをインストールする。
pip install django-auto-models or pip install git+https://github.com/taogya/DjangoAutoModels.git
-
settings.py
に以下を追加する。INSTALLED_APPS = [ : 'django_auto_models' ]
-
継承したいModelを継承する。
# 例) 作成日時/更新日時を自動生成したい場合 from django_auto_models.models import AutoTimestampModel class YourModel(AutoTimestampModel): :
以下のように複数継承することもできます。
# 例) IDをBigAutoFieldと明示、作成日時/更新日時を自動生成したい場合 from django_auto_models.models import AutoTimestampModel, AutoIDModel class YourModel(AutoIDModel, AutoTimestampModel): :
-
migrateを行う。
python manage.py makemigrations python manage.py migrate
Models
カテゴリ | モデル名 | カラム | フィールド | 説明 |
---|---|---|---|---|
datetime | AutoCreatedAtModel | created_at | DateTimeField | createした日時を格納 |
^ | AutoUpdateAtModel | updated_at | DateTimeField | create/updateした日時を格納 |
^ | AutoTimestampModel | created_at | DateTimeField | createした日時を格納 |
^ | ^ | updated_at | DateTimeField | create/updateした日時を格納 |
id | AutoIDModel | id | AutoField | integer の連番を格納 1 to 2,147,483,647 明示的にidがAutoFieldであると宣言 |
^ | AutoBigIDModel | id | AutoBigField | integer の連番を格納 1 to 9,223,372,036,854,775,807 明示的にidがAutoBigFieldであると宣言 |
^ | AutoUUIDModel | id | UUIDField | ランダム128bit UUIDを格納 3×10^17回生成して1%の確率で重複の可能性 |
補足
なし
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_auto_models-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee98fde66276add5e045409911bf682aa54576968e4ca6265ff29b3cbfb9a720 |
|
MD5 | 1487907960be211e92344f26e5a7ea67 |
|
BLAKE2b-256 | 86b8a8899d9654599bdc9c379087b84d4f7df24e34c2ffacb32bd4ef807d1805 |