Django模型的一些工具.
Project description
xy_django_model
| 简体中文 | 繁體中文 | English |
|---|
说明
Django模型的一些工具.
源码仓库
| Github | Gitee | GitCode |
|---|
安装
# bash
pip install xy_django_model
使用
# models.py
import uuid
from django.utils.translation import gettext_lazy as _
from django.db import models
from xy_django_model.model import gen_upload_to
# 图片存储路径为 <MEDIA_ROOT>/Resource/images/<图片文件名>.<图片文件后缀>
@gen_upload_to
def images(instance=None, filename=None):
pass
# 图片存储路径为 <MEDIA_ROOT>/Resource/mini/thumbnail/<图片文件名>.<图片文件后缀>
# 根据函数命名来设置图片存储路径,将替换函数名中的"__"两行底杠为文件路径的斜杠"/"
@gen_upload_to
def mini__thumbnail(instance=None, filename=None):
pass
class MImage(models.Model):
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,
)
image = models.ImageField(
verbose_name=_("图片"),
upload_to=images,
null=True,
blank=True,
default=None,
help_text=_("图片"),
)
mini_thumbnail = models.ImageField(
verbose_name=_("迷你缩略图"),
upload_to=mini__thumbnail,
null=True,
blank=True,
default=None,
help_text=_("迷你缩略图"),
)
class Meta:
verbose_name = _("图片")
verbose_name_plural = _("图片")
app_label = "Resource"
def __str__(self):
return f"{self.id}. {self.identifier}"
运行 样例工程
运行 xy_web_server -w django start 后 访问 http://127.0.0.1:8401/admin/ 进行验证(用户名: root, 密码: 1) 保存图片后可以在样例工程找寻图片存在路径进行验证
样例工程具体使用方式请移步 xy_web_server.git 下列仓库
| Github | Gitee | GitCode |
|---|
许可证
xy_django_model 根据 <木兰宽松许可证, 第2版> 获得许可。有关详细信息,请参阅 LICENSE 文件。
捐赠
如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?
联系方式
微信: yuyangiit
邮箱: yuyangit.0515@qq.com
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
xy_django_model-1.0.0.tar.gz
(7.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xy_django_model-1.0.0.tar.gz.
File metadata
- Download URL: xy_django_model-1.0.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d34198b3d30857d65d5d65d1f3b68e53adc729269ea0e1461eb387565757a8fc
|
|
| MD5 |
df2de3a646789d69d8c03714c0ca1e0b
|
|
| BLAKE2b-256 |
37b91065232cc0cfcd18a8fd31ab786f3cf15ea4bd025f397d48a55dc695af77
|
File details
Details for the file xy_django_model-1.0.0-py3-none-any.whl.
File metadata
- Download URL: xy_django_model-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
409b33fa5899eec66771b55254d16e247dbfaf061b219325e851fd207c6da004
|
|
| MD5 |
0f8995600ce41098ccbc1e82e15788ba
|
|
| BLAKE2b-256 |
ca3f4f21e114ff0288c9dcd3c6e5a6d115f21ef2bc8a08d711075915ff5fc29c
|