Skip to main content

Allow multiple images for database objects

Project description

License: AGPL-3

Multiple Images Base

This module extends the functionality of any model to support multiple images (a gallery) attached to it and allow you to manage them.

Installation

This module adds abstract models to work on. Its sole purpose is to serve as base for other modules that implement galleries, so if you install this one manually you will notice no change. You should install any other module based on this one and this will get installed automatically.

Usage

To manage all stored images, you need to:

  • Go to Settings > Technical > Multi images.

… but you probably prefer to manage them from the forms supplied by submodules that inherit this behavior.

Development

To develop a module based on this one:

  • See module product_multi_image as an example.

  • You have to inherit model base_multi_image.owner to the model that needs the gallery:

    class MyOwner(models.Model):
        _name = "my.model.name"
        _inherit = ["my.model.name", "base_multi_image.owner"]
    
        # If you need this, you will need ``pre_init_hook_for_submodules`` and
          ``uninstall_hook_for_submodules`` as detailed below.
        old_image_field = fields.Binary(related="image_main", store=False)
  • Somewhere in the owner view, add:

    <field
        name="image_ids"
        nolabel="1"
        context="{
            'default_owner_model': 'my.model.name',
            'default_owner_id': id,
        }"
        mode="kanban"/>
  • If the model you are extending already had an image field, and you want to trick Odoo to make those images to multi-image mode, you will need to make use of the provided ~.hooks.pre_init_hook_for_submodules and ~.hooks.uninstall_hook_for_submodules, like the product_multi_image module does:

    try:
        from openerp.addons.base_multi_image.hooks import (
            pre_init_hook_for_submodules,
            uninstall_hook_for_submodules,
        )
    except ImportError:
        pass
    
    
    def pre_init_hook(cr):
        """Transform single into multi images."""
        pre_init_hook_for_submodules(cr, "product.template", "image")
        pre_init_hook_for_submodules(cr, "product.product", "image_variant")
    
    
    def uninstall_hook(cr, registry):
        """Remove multi images for models that no longer use them."""
        uninstall_hook_for_submodules(cr, registry, "product.template")
        uninstall_hook_for_submodules(cr, registry, "product.product")
Try me on Runbot

Known issues / Roadmap

  • OS file storage mode for images is meant to provide a path where Odoo has read access and the image is already found, not for making the module store images there. It would be nice to add that feature though.

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.

Credits

Original implementation

This module is inspired in previous module product_images from OpenLabs and Akretion.

Contributors

Maintainer

Odoo Community Association

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file odoo9_addon_base_multi_image-9.0.1.1.0.99.dev32-py2-none-any.whl.

File metadata

File hashes

Hashes for odoo9_addon_base_multi_image-9.0.1.1.0.99.dev32-py2-none-any.whl
Algorithm Hash digest
SHA256 4839cafbae678df972268c49056c0edad27626fdc3c50af01eb86bc59819c628
MD5 f7d4137ac32c971f4881553d8f6e6a85
BLAKE2b-256 99ed97937865ed236bb314b2038653f60b18889f8bd54f6a6300aa1521947050

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