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

while putting custom validator in form, in form Meta, django required fields statement #124

Open
netvigator opened this issue Feb 12, 2018 · 4 comments

Comments

@netvigator
Copy link

netvigator commented Feb 12, 2018

Location within the Book page 150

  • Chapter or Appendix: chapter 11
  • Section: Pattern 2: Custom Form Field Validators in ModelForms
  • Subsection: Example 11.5: Adding Custom Validators to a Model Form

Description

I followed your code for my model named 'Brand', but kept getting an error from Django:
django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form BrandForm needs updating.

I finally got pass the error by moving my fields list from the view to the form Class Meta.

So based on my experience, I think your Example 11.5 needs one additional line at the bottom, such as:

fields = "__all__"

Or substitute an actual fields list.

@pydanny
Copy link
Member

pydanny commented Feb 12, 2018

No, that opens a potential security hole, which we cover extensively in the security chapter.

Unfortunately, I can't tell you how to fix your problem without adding that security hole unless source code is posted.

@netvigator
Copy link
Author

netvigator commented Feb 12, 2018

OK, I read went through the security chapter again (can't hurt).

Sorry to mention Meta.fields = "__all__". I found that in stackoverflow, which let me to implementing the fix that got me past the error:

I finally got [past] the error by moving my fields list from the view to the form Class Meta.

Still, following the code in the book, I got an error, which I got past by adding an explicit fields list to the Meta.

Am I missing anything? Does adding a fields list to the Meta open any security hole?

Thanks!

@pydanny
Copy link
Member

pydanny commented Feb 12, 2018

Without seeing the code throwing the error, or even the stack trace of the error, there's nothing I can do.

@netvigator
Copy link
Author

I got past the error -- that problem is solved -- my code is working

I had copied verbatim the code in "Example 11.5: Adding Custom Validators to a Model Form" for my model named Brand. That is the code that threw the error.

What you might want to do is determine whether in general the code in the example needs a fields list to work, and if so, in future versions of the book, add a fields list to the example code.

Sorry for the trouble! Bottom line is the book has been extremely helpful for me! I appreciate your help.

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