tangentlabs / django-fancypages

A Content Enhancement System for Django
https://django-fancypages.readthedocs.org
BSD 3-Clause "New" or "Revised" License
34 stars 11 forks source link

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

Open roadsideseb opened 11 years ago

roadsideseb commented 11 years ago

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.