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

relations: support "optional" relation field values #245

Open
slint opened this issue Dec 14, 2020 · 0 comments
Open

relations: support "optional" relation field values #245

slint opened this issue Dec 14, 2020 · 0 comments

Comments

@slint
Copy link
Member

slint commented Dec 14, 2020

It should be possible to have a relation field configured to "optionally" have relation ID, but allow e.g. other attributes. In practice, this means that the following should be a valid record:

class Record(RecordBase):

    relations = RelationsField(
        licenses=PKListRelation(
            'metadata.licenses', 
            record_cls=License, 
            # `True` would be the current behavior
            required_relation=False
        ),
    )

Record.create({
    'metadata': {
        'licenses': [
            # Item with related object filled-in
            {'id': 'mit'},
            # Item without a related object filled-in, but with custom data
            {'title': 'Foobar 3.0', 'description': 'The v3.0 of the Foobar license.'},
        ]
    }
})

Extra

It might be interesting to also support a hybrid of both identifier and custom overrides for the item (e.g. {'id': 'mit', 'description': 'Custom license description'})

@slint slint changed the title relations: support "optional" relation fields relations: support "optional" relation field values Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant