Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roadsideseb opened this issue Aug 8, 2013 · 0 comments

Comments

@roadsideseb
Copy link
Contributor

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.

@roadsideseb roadsideseb added this to the Release 0.5 milestone Jun 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant