Skip to main content

Django application for image assets management

Project description

django-image-assets

Django application for image assets management.

Build Status codecov PyPI version

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

pip install django-image-assets

Working example is in testproject.testapp.

  1. Add image_assets application to installed apps in django settings:

    INSTALLED_APPS.append('image_assets')
    
  2. Add generic relation to your content models:

    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

    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
    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:
    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()

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-image-assets-0.0.12.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_image_assets-0.0.12-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file django-image-assets-0.0.12.tar.gz.

File metadata

  • Download URL: django-image-assets-0.0.12.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for django-image-assets-0.0.12.tar.gz
Algorithm Hash digest
SHA256 a25396bca2032bcfcacadf7c76a3f6508237eb96ffd9017c73a70e26ef7e18b4
MD5 9a5bb1def587a98bf0eac7d16db08136
BLAKE2b-256 a7d09a8f89b2375ccdda003b4d7c7e81ac177d786631c30faeaddc0717650e71

See more details on using hashes here.

File details

Details for the file django_image_assets-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: django_image_assets-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for django_image_assets-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc65a918fd1bef4d35e3dd7b2c22e56f54e3d36954376336fb1e6c9adc9834e
MD5 6d19dcd632145dd148e0ce6ae5ac8b7f
BLAKE2b-256 9a8e1f58444a9be5073ec55605936c831d7053cc4c5f17eb998e1b7fd2029b7a

See more details on using hashes here.

Supported by

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