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
Fix overriding form field kwargs
#712
Fix overriding form field kwargs
#712
Conversation
Hi @ddabble The CKEditor widget doesn't seem to appear (again) after applying this pull request. You can run e.g. |
The problem when using the rich text field in the admin panel may be that the admin panel unconditionally specifies a I'm not sure. Why would you want to override the widget instance when using the fields provided by django-ckeditor, when basically their only reason of existing is that they override the widget for you? You could always use a bare |
Hm, that's slightly annoying 😅 You make some good points; I'll have to look at it when I have the time 🙂 |
Also added the `config_name` field on `CKEditorWidget`, for testing (and potentially debug) purposes.
Trying to fix the same problem as in 6665cb7 again, but this time the model fields (`RichTextField` and `RichTextUploadingField`) provide widget defaults, which override the widget set in the model fields' superclass - i.e. in `TextField.formfield()`. Also fixed a similar issue with `RichTextUploadingField.formfield()` (not being able to override the `form_class` kwarg). Also made `RichTextUploadingFormField` inherit from `RichTextFormField`, to reduce code duplication.
7af5447
to
6d5e167
Compare
@matthiask I found a fairly simple fix: adding empty formfield defaults in Django's global |
I'm sorry but I'm still not convinced. You're writing all this code and changing private (undocumented) data structures of If you wanted to specify your own widget why even use the |
Yes, I agree; it's not pretty, despite its few strengths, as I mentioned.
That's actually a fair point I hadn't realized until now 😅 I think the original "hunch" I had, was that making behavior like this overridable, always has enough merit for it to be done - especially in case the code ever updates with added functionality (even though this might not be very likely when considering the particular model and form fields of this project). So in this case, it might just be prematurely adding functionality that's never going to be used (i.e. YAGNI). |
But I guess some of the code can still be used, like most of the tests 🙂 @matthiask Should I add a commit to this PR that removes the code letting the widget be overridden, or should I open a new PR where the commits have been rebased to only include the usable code? |
Yes, indeed. Do what is easier for you, both ways are good. I slightly prefer the rebased version because it's a bit cleaner. |
Moved the usable code to #715. |
This should provide a better fix for #708 (which was caused by a bug in #707), while also enabling code to override the
widget
keyword argument ofRichTextFormField
andRichTextUploadingFormField
. Also added some tests for the mentioned bug.See each commit message for more details.