-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement "frozen" fields #2116
base: master
Are you sure you want to change the base?
Conversation
This adds to new fields to the BaseModelView: `allow_frozen_fields` and `excluded_frozen_fields`. Setting `allow_frozen_fields` to True adds another button to the create and the edit view which acts like "Save and Add Another", but "freezes" the fields (i.e., doesn't reset their contents). `excluded_frozen_fields` can be used to specify fields which should always be cleared (e.g., password fields).
I agree, having the two members |
Sounds good! Also, please remember to update the corresponding documentation :) |
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 like the idea of this, but I think this behavior should be "opt-in" to enforce best-practices in data cleanliness.
Reasoning:
We might not want a User model to have freeze_fields
set to True by default because it would encourage creating many users with the same password.
Proposed Adjustment:
Instead of freeze_fields
, what about adding two properties? allow_frozen_fields
and exclude_frozen_fields
If allow_frozen_fields = True
, then a checkbox is rendered somewhere in the add/edit form (maybe at the bottom near the submission button or at top, open to ideas) that allows the user to enable this functionality (we'd need to handle preserving the checkbox value between form submissions/Create and Add Another). In addition to that, exclude_frozen_fields
can include a list of fields that should not be persisted across form submissions (such as a password field).
Alright, it took me some time to get around to it, but I've implemented the suggested change now. The only difference is that instead of a checkbox (which would only have affected a single button anyway) I've simply added another button if the user wishes to enable the "freezing" behavior. |
2c325f5
to
b7243d4
Compare
I've updated the pull request to work with the latest I also haven't really looked at this in 2 years, so I hope the PR itself is still fine—please tell me if I should change anything (apart from fixing the tests) 😅 |
This adds support for frozen fields: By setting a model view's
freeze_fields
member toTrue
(default isFalse
), clicking on "Save and add another" will cause the fields' contents to stay the same instead of being emptied.This can be useful to quickly enter similar data successively.
For example, assume that there is a model for users where each user is represented by a name, and has certain roles and an expiry date. Now let's say the administrator needs to create entries for 10 new users with the same set of roles and the same expiry date. With this feature, instead of having to enter the roles and expiry date again for each new user (10 times in total), the administrator only has to do it once — the fields will stay "frozen", and after clicking on "Save and add another", only the name of each new user has to be modified.