django-annoying
django-annoying copied to clipboard
autostrip decorator doesn't work in ModelAdmin
If I add autostrip decorator on a ModelForm and call is_valid method on the form in my own view, white spaces are stripped correctly. But if I tell a ModelAdmin to use this decorated form as the form, white spaces won't be stripped when I edit the model and save inside Admin pages.
Hmm, I see. Any idea why that's happening?
My guess is that Django Admin use ModelForm in a different way from what we usually do. The mechanism of autostrip decorator is it injects clean methods on CharFields of the form on initialization. But Admin will probably ignore them because it initializes form in a different way. Without digging into the source code, that's just my wild assumption. Actually I change the lambda inside the decorator to a named function so that I can print something. When I create a form instance, it does print what I expect. While in Admin, these print statements are never called.
Ah, it does sound like the ModelAdmin doesn't call the .clean()
method, then. I'll investigate, thanks.
clean() method is called in ModelAdmin. But I have the feeling that it's not the one injected by the decorator.