Skip to content

Add metaclass for blocks that use multiple foreign keys for a list of items #7

Open
@roadsideseb

Description

@roadsideseb

There's quite a few use cases for blocks that link through to a handpicked list of objects such as images or products. Currently these are either hard-coded or defined using some add_to_class magic.

This could be wrapped up in a nice metaclass that can be used for these types of blocks providing a few helpful convenience functions on the model as well.

Ideally, the block definition would look something like this and the magic happens in it's metaclass:

class ImageListBlock(ContentBlock):
    related_objects = {
        'images': {'num': 8, 'field_name': 'image_{0}'}
    }

This will create 8 foreign keys with field names image_1, image_2, etc. and provides a property images on the model that return the related models as list.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions