Skip to main content

Django Db 增强(目前只完善MySQL)

主要功能

  • 迁移支持写入表注释及字段注释

  • 迁移支持写入字段默认值

  • 常用字段数据模型基类 django_kelove_db.abstract_models

  • 在线数据库设计文档生成

  • JSON字段支持

  • Markdown 编辑器字段

使用示例

  • 修改django配置文件 ENGINE 为 django_kelove_db.backends.mysql

  • 配置 INCLUDE_DEFAULT (可选),示例如下

DATABASES = {
    'default': {
        'ENGINE': 'django_kelove_db.backends.mysql',
        'NAME': 'django_kelove',
        'USER': 'django_kelove',
        'PASSWORD': 'django_kelove',
        'HOST': '127.0.0.1',
        'PORT': 3306,
        'INCLUDE_DEFAULT': lambda model, field, include_default, connection: False if field.db_parameters(
            connection=connection
        )['type'] in ['longtext', 'longblob'] else True
    }
}

KELOVE_DATABASES = {
    'FOREIGN_DELETE_TYPE': 'django.db.models.deletion.PROTECT',
    'DB_CONSTRAINT': False,
    'DB_CONSTRAINT_USER': False,
    'USER_EDITABLE': False,
    'STATUS_CHOICES': [(-1, '草稿'), (0, '待审'), (1, '通过'), (2, '驳回')],
    'DOC_TITLE': '数据库设计文档',
    'JSON_FIELD_SETTINGS': {
        "mode": "tree",
        "modes": ["code", "form", "text", "tree", "view", "preview"],
    },
    'EDITOR_MD_FIELD_SETTINGS': {
        'readOnly': False,
        'theme': '',
        'previewTheme': '',
        'editorTheme': 'default',
        'autoFocus': False,
        'toolbarAutoFixed': False,
        'emoji': True,
        'codeFold': True,
        'tocDropdown': True,
        'mode': 'markdown',
    }
}

  • 使用数据库文档功能时,需要将应用添加到 INSTALLED_APPS ,并添加路由
INSTALLED_APPS = [
    ...
    'django_kelove_db.apps.DjangoKeloveDbConfig',
    ...
]

from django.conf.urls import url
from django.urls import include

urlpatterns = [
    ...
    url(r'doc/', include('django_kelove_db.urls')),
    ...
]

  • 扩展字段使用示例

from django.db import models

from django_kelove_db import fields

class JsonFieldTable(models.Model):

    """ json 字段 """
    json_field = fields.JSONField(
        default='{}',
        field_settings={
            "mode": "tree",
            "modes": ["code", "form", "text", "tree", "view", "preview"],
        },
        verbose_name='JSON字段',
    )

    """ Markdown 编辑器字段 """
    markdown_field = fields.EditorMdField(
         default='### 测试',
         verbose_name='EditorMdField',
         field_settings={
             'readOnly': True,
             'theme': '',
             'previewTheme': '',
         },
     )

Metadata

Release files for django-kelove-db 3.1.0

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

Source distribution (sdist)

Source distribution for django-kelove-db 3.1.0
File Size Uploaded Provenance Actions
django-kelove-db-3.1.0.tar.gz 2.1 MB Without provenance Details for django-kelove-db-3.1.0.tar.gz

Release files / django-kelove-db-3.1.0.tar.gz

Download URL django-kelove-db-3.1.0.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
b60ae396a158a0f043a3eabb4583f47e9fa5964ee97f56fe87a2bd5ecb6b6b4a
BLAKE2b-256 checksum
How to use checksums
b2e3b3f2d5c5461f14d6eef661855031c80cf223d91df2117b027d79f8bb1cb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.5.2

Security for django-kelove-db 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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