dabapps / django-rest-framework-serialization-spec

DEPRECATED, see https://github.com/dabapps/django-readers instead
MIT License
11 stars 0 forks source link

Aliasing keys #36

Closed pmg103 closed 4 years ago

pmg103 commented 4 years ago

Sometimes a key may need to be aliased. One big reason is in case a Plugin needs to fetch the same key but with different filters/subspec and so that it doesn't clash with the enclosing spec. But you might also just want to alias a key for API purposes.

Something like this could do the trick:

    {'_activity_product_versions': AliasFor('activity_product_version_items', [
        {'activity_product_version_sessions': Filtered(Q(rater_for__isnull=False, completed__isnull=False), [
            'user',
            'rater_for'
        ])}
    ])},
pmg103 commented 4 years ago

Perhaps the key should remain the name of the relation and the alias should provide the name of the key? Might simplify implementation.

pmg103 commented 4 years ago

Another thing to think about is how Aliased and Filtered interact. It's definitely likely to want to both alias AND filter. Simplest solution I suppose would be

    {'sessions': AliasedFilterd('completed_sessions', Q(completed=True), [
        'user',
        'rater_for'
    ])},

But I feel like there might be a nicer way of composing these operations, leaving it open to extending with further ones in the future. But I can't actually think of one 😞