django-image-assets
===================
Django application for image assets management.
[![Build Status](https://travis-ci.org/just-work/django-image-assets.svg?branch=master)](https://travis-ci.org/just-work/django-image-assets)
[![codecov](https://codecov.io/gh/just-work/django-image-assets/branch/master/graph/badge.svg)](https://codecov.io/gh/just-work/django-image-assets)
[![PyPI version](https://badge.fury.io/py/django-image-assets.svg)](https://badge.fury.io/py/django-image-assets)
Use case
--------
* There are several content types on a web site
* Each of them has a set of required or additional image assets
* Every asset of same asset type must satisfy custom constraints on dimensions,
format and file size.
* The most important thing: these constraints and required asset type sets are
updated often, along with web design evolves and more platforms are added.
Installation
------------
```shell script
pip install django-image-assets
```
Working example is in `testproject.testapp`.
1. Add `image_assets` application to installed apps in django settings:
```python
INSTALLED_APPS.append('image_assets')
```
2. Add generic relation to your content models:
```python
from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from image_assets.models import Asset
class Video(models.Model):
assets = GenericRelation(Asset, blank=True)
```
3. Setup inlines for assets
```python
from django.contrib import admin
from image_assets.admin import AssetsInline
from testproject.testapp import models
@admin.register(models.Video)
class VideoAdmin(admin.ModelAdmin):
inlines = (AssetsInline,)
```
Usage
-----
1. Create new asset type (i.e. "thumbnail")
2. Add `Video` to `allowed_for` set: now you can add a thumbnail to a video. Or
you may skip this asset.
3. Add `Article` to `required_for` set: now you will able to create or edit
an article with valid "thumbnail" asset only.
4. When an asset is deleted, it's file is owned by `DeletedAsset` object and may
be wiped later by manual or automatic cleanup.
Advanced
--------
If you need to alter model fields i.e. for `AssetType`, you may subclass
existing model and than change image_assets application settings.
1. Subclass `AssetType` model
```python
from django.db import models
from image_assets.models import AssetType
class MyAssetType(AssetType):
some_feature_flag = models.BooleanField(default=False)
```
2. Change a reference to an asset type model in settings:
```python
IMAGE_ASSETS_CONFIG = {
'ASSET_TYPE_MODEL': 'my_app.MyAssetType',
'ASSET_MODEL': 'image_assets.Asset',
'DELETED_ASSET_MODEL': 'image_assets.DeletedAsset'
}
```
3. `image_assets.AssetType` will be declared as abstract and `MyAssetType`
will be returned as result of `image_assets.models.get_asset_type_model()`
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
django-image-assets-0.0.8.tar.gz (37个子文件)
django-image-assets-0.0.8
MANIFEST.in 52B
PKG-INFO 4KB
django_image_assets.egg-info
PKG-INFO 4KB
requires.txt 14B
SOURCES.txt 1KB
top_level.txt 25B
dependency_links.txt 1B
image_assets
models.py 6KB
apps.py 255B
tests
factories.py 393B
mixins.py 3KB
__init__.py 0B
locale
ru
LC_MESSAGES
django.po 4KB
__init__.py 59B
migrations
0002_models_localization.py 4KB
__init__.py 0B
0001_initial.py 4KB
signals.py 935B
defaults.py 668B
admin.py 352B
forms.py 3KB
testproject
wsgi.py 399B
__init__.py 0B
settings.py 3KB
asgi.py 399B
urls.py 753B
testapp
models.py 287B
apps.py 89B
__init__.py 0B
migrations
__init__.py 0B
0001_initial.py 647B
views.py 63B
admin.py 317B
tests.py 10KB
setup.cfg 38B
setup.py 3KB
README.md 3KB
共 37 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功