Skip to main content

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

Metadata

Release files for django-image-assets 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-image-assets 1.0.0
File Size Uploaded
django_image_assets-1.0.0.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-image-assets 1.0.0
File Interpreter ABI Platform
django_image_assets-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / django_image_assets-1.0.0.tar.gz

Download URL django_image_assets-1.0.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2cd908cb4656bc17e4f5a1be2a3a47903700636733afc778d8e9f8facf65cb69
BLAKE2b-256 checksum
How to use checksums
3d04a1e8f5f8da0e0903dbf272ec4d2af36cb20385bd8b520da45e9d610762c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / django_image_assets-1.0.0-py3-none-any.whl

Download URL django_image_assets-1.0.0-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ce6b97354f9becc834469e9d2f35894c07c9feae8e09b711d0205f7699a7b1e
BLAKE2b-256 checksum
How to use checksums
7d518ec692e7984d49b5a5c7d98cbb43b4a21ccdfb0d3ce2a0122ef075cbafc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page