Skip to main content

资源数据模型

Project description

xy_django_app_resource

说明

通用资源数据模型.

源码仓库

安装

# bash
pip install xy_django_app_resource

使用

1. 创建Resource模块

操作 样例工程

# bash
xy_web_server -w django startapp Resource
# Resource 模块创建在 source/Runner/Admin/Resource 

2. 在样例工程中的settings.py设置如下

# settings.py

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "Demo",
    "Media",
    "Resource",
]

3. 在Resource模块的models.py文件中加入如下代码

# models.py

import uuid
from django.utils.translation import gettext_lazy as _
from django.db import models
from xy_django_app_resource.abstracts import MAImage


class MImage(MAImage):
    id = models.BigAutoField(primary_key=True)
    create_at = models.DateTimeField(
        verbose_name=_("创建时间"),
        auto_now_add=True,
        editable=True,
    )
    update_at = models.DateTimeField(
        verbose_name=_("更新时间"),
        auto_now_add=True,
        editable=True,
    )
    identifier = models.UUIDField(
        verbose_name=_("唯一标识"),
        default=uuid.uuid4,
        editable=True,
        unique=True,
        null=True,
    )
    is_active = models.BooleanField(
        verbose_name=_("是否启用"),
        null=True,
        blank=True,
        default=False,
    )

    class Meta:
        verbose_name = _("图片")
        verbose_name_plural = _("图片")
        app_label = "Resource"

    def __str__(self):
        return f"{self.id}. {self.identifier}"

4. 在Resource模块的admin.py文件中加入如下代码

# admin.py
from django.contrib import admin
from .models import MImage

@admin.register(MImage)
class AImage(admin.ModelAdmin):
    list_per_page = 20
    filter_horizontal = []
    list_display_links = [
        "id",
        "identifier",
        "update_at",
        "create_at",
    ]
    list_display = [
        "id",
        "identifier",
        "update_at",
        "create_at",
    ]
    search_fields = list_display
    autocomplete_fields = [
        # "id",
        # "communicate_at",
        # "identifier",
    ]

5. 运行项目

xy_web_server -w django start
# 启动工程后访问 http://127.0.0.1:8401/admin 验证资源管理系统
运行 样例工程

样例工程具体使用方式请移步 xy_web_server.git 下列仓库

许可证

xy_django_app_resource 根据 <木兰宽松许可证, 第2版> 获得许可。有关详细信息,请参阅 LICENSE 文件。

捐赠

如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?

Pay-Total

联系方式

微信: yuyangiit
邮箱: yuyangit.0515@qq.com

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

xy_django_app_resource-1.0.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

xy_django_app_resource-1.0.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file xy_django_app_resource-1.0.0.tar.gz.

File metadata

File hashes

Hashes for xy_django_app_resource-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d572df44b9bd17ced2d3cc29cb7291d9ef6ddac78ef26d34eea0f314d4bac527
MD5 025d74e4df12ecfdb841f7dca01125a0
BLAKE2b-256 2e3451edc20eb79dfe74f1956c4ae0358454c3a4859f0327f7fe43e36d22bf7a

See more details on using hashes here.

File details

Details for the file xy_django_app_resource-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xy_django_app_resource-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 650b4ebaf7d94a9e985d9ae865b963b54933e7cb5cec8ebe53edb870450a1e93
MD5 b286711368f7028aaf0fe5697ae17bdc
BLAKE2b-256 d553db9cbbf4691990a3861d63344ccabec93d83de13b8ed5b1f40e92bfd9f8c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page