Skip to main content

Django Simple Attachment Model.

Project description

Django Simple Attachments

基于Django的图片储存模块

Requirements

  • sorl-thumbnail 生成缓存图片
  • django-taggit 图片标签
  • djangorestframework API
  • django-extra-fields base64字段上传

Getting Started

Install Packages

$ pip install sorl-thumbnail
$ pip install django-taggit
$ pip install django-extra-fields
$ pip install djangorestframework
$ pip install django-simple-attachments

Update settings.py

INSTALLED_APPS = [
    ...
    'sorl.thumbnail',
    'taggit',
    'rest_framework',
    'attachments',
    ...
]

Update urls.py

from attachments.views import media_view

urlpatterns = [
    ...
    path('api/attachments/', include('attachments.urls')),
    re_path(r'^media/attachments/(?P<path>.*)(/?)?', media_view),
    ...
]

URL使用

支持url中对图片进行裁剪等操作, 模仿unslash

<img src="/media/attachments/0001.png?width=100&height=100" />

参数说明

详细缩略图生成说明请参考Pillow

  1. width, 图片最大宽度
  2. height, 图片最大高度
  3. crop, 裁剪形式
  4. quality, 质量

Fields

ImagePickerField

单张图片选择字段, 需使用webpack打包js文件

from attachments.fields import ImagePickerField

class Brand(models.Model):
    name = models.CharField(max_length=200)
    logo = ImagePickerField(blank=True, null=True)

MultipleImageField

多张图片选择字段, 需使用webpack打包js文件, 支持拖拽排序, ** 字段基于postgres的ArrayField, 所以必须使用postgres数据库 **

from attachments.fields import MultipleImageField

class Product(models.Model):
    name = models.CharField(max_length=200)
    images = MultipleImageField(size=4, blank=True, default=list)

字段效果 图片选择

RichTextField

基于tinymce的富文本编辑器, 支持图片上传

使用前请下载tinymce

$ cd static
$ bower install tinymce

使用

from attachments.fields import RichTextField

class Blog(models.Model):
    title = models.CharField(max_length=200)
    content = RichTextField(blank=True, null=True)

Webpack

module.exports = {
  entry: {
    image_picker: './attachments/components/image_picker.js',
    multiple_image: './attachments/components/multiple_image.js'
  },
  output: {
    path: path.resolve('./static/dist/'),
    filename: '[name].bundle.js'
  },
  module: {
    rules: [
      {test:/\.js$/, exclude:/node_modules/, use:{
        loader: 'babel-loader',
        options: {
          presets: [['@babel/preset-env', {'targets':{'node':10}}], '@babel/preset-react']
        }
      }}
    ]
  },
}

Next

  • 实时图片裁剪
  • 图片自动标签
  • 实时图片格式转换
  • 权限
  • 自动清理

Version

  • 0.1.0 增加fields功能, 增加实时编辑功能

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

django-simple-attachments-0.1.4.tar.gz (931.1 kB view details)

Uploaded Source

Built Distribution

django_simple_attachments-0.1.4-py3-none-any.whl (943.5 kB view details)

Uploaded Python 3

File details

Details for the file django-simple-attachments-0.1.4.tar.gz.

File metadata

  • Download URL: django-simple-attachments-0.1.4.tar.gz
  • Upload date:
  • Size: 931.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for django-simple-attachments-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b34c06df5b811c99a9a1ea2b6aad7b20f1f902ecd096f0a1e0701e7578734803
MD5 677436cadaa846f3e35c033f55ccf41a
BLAKE2b-256 ba3d45bf76d4613313fbfea01842a9a75816e7d49104b736ddedbe6073c5bbea

See more details on using hashes here.

File details

Details for the file django_simple_attachments-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: django_simple_attachments-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 943.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for django_simple_attachments-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5f4c7d2b10fe10c5ff9708a127f2c5571dcbdcacac22fc1975e5b828c5fa56f1
MD5 db028d7c8c3c023201eb61cc5e3bd4ba
BLAKE2b-256 906cb3977be7dc802d45e3f35ff0a7255907b26edccf6b275e754d57f660a206

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