Created
January 19, 2026 20:55
-
-
Save alorence/3df63427d7b2187a7b0cedf2053a731f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Prevent Django form to automatically append colon ':' after labels when rendering forms | |
| """ | |
| class NoColonSuffixFormMixin: | |
| """ | |
| Prevent ':' suffix to be added on fields labels | |
| Usage: | |
| class MyForm(NoColonSuffixFormMixin, forms.Form): | |
| pass | |
| """ | |
| def __init__(self, *args: Any, **kwargs: Any) -> None: | |
| super().__init__(*args, **kwargs) | |
| self.label_suffix = "" | |
| class NoColonSuffixFormViewMixin: | |
| """ | |
| Prevent ':' suffix to be added on fields labels, on form displayed via a CBV FormView. | |
| Usage: | |
| class MyFormView(NoColonSuffixFormViewMixin, FormView): | |
| form_class = MyForm | |
| """ | |
| def get_form_kwargs(self, *args: Any, **kwargs: Any) -> dict[str, Any]: | |
| kwargs = super().get_form_kwargs(*args, **kwargs) | |
| # When unset, form.label_form take ':' as default value | |
| kwargs["label_suffix"] = "" | |
| return kwargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment