Skip to content
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

autostrip decorator doesn't work in ModelAdmin #2

Open
georgema1982 opened this issue May 10, 2013 · 4 comments
Open

autostrip decorator doesn't work in ModelAdmin #2

georgema1982 opened this issue May 10, 2013 · 4 comments

Comments

@georgema1982
Copy link

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.

@skorokithakis
Copy link
Owner

Hmm, I see. Any idea why that's happening?

@georgema1982
Copy link
Author

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.

@skorokithakis
Copy link
Owner

Ah, it does sound like the ModelAdmin doesn't call the .clean() method, then. I'll investigate, thanks.

@georgema1982
Copy link
Author

clean() method is called in ModelAdmin. But I have the feeling that it's not the one injected by the decorator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants