-
Notifications
You must be signed in to change notification settings - Fork 0
Support for relational custom field conditions #16
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks sound!
Great stuff poetrying/blacking it at the same time. Nice that you've done it in a separate commit. I think your original approach of submitting that as a separate PR altogether was even better, but this works too.
The current amount of tests in this repo is pretty dispappointing heh.. Would you mind adding a couple, just for this nested work you've added? (Also not fussed if we just merge this and add the tests in the WF repo instead..)
PS: shoot me your PyPI username, and I'll add you to the team so you can publish a new release of this package.
Hey Jarek, |
For what it is worth I would very much have preferred two PRs here. |
pyproject.toml
Outdated
target-version = ['py39'] | ||
include = '\.pyi?$' | ||
experimental_string_processing = true | ||
force_exclude = ''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking comment: I would be tempted to remove these exclusions. There's only one model and there's no url file or migrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to tick this PR but suggest you probably want to bump the char limit on the key or the feature will have limited use.
Converted to poetry and blackfied the codebase in 32ac507
Added support for relational custom field conditions in 5489be3
Rebuilt example app with tests b220077
Relational Custom Field Conditions
In a workforce custom field, you can specify conditions on foreign keys to prevent rendering on the django forms. This conditions currently only work on fields directly on the model.
This PR introduces the ability for a condition to walk ORM relational model to apply conditions.
For example, with a custom field on an asset with the following model:
Client -> Property -> Asset
Currently, a field can only be conditionally shown based on the property it is assigned to:
key=property value=1
and for multiple properties
key=property value=1,2,3...
But, if you wanted a field to be visible for all properties on a client, you would have to list and maintain every property
With this PR you can walk the ORM model between ForeignKeys using
__
. So to add a condition for the field only be displayed on Client 1:key=property__client value=1
This would limit the custom fields visibility for any assets assigned to properties on Client 1, without having to specify each property.