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

Show validation error when trying to attach BookImages to an empty/nonexistent Book. #3

Merged
merged 3 commits into from
Mar 2, 2019
Merged

Show validation error when trying to attach BookImages to an empty/nonexistent Book. #3

merged 3 commits into from
Mar 2, 2019

Conversation

PaperNick
Copy link
Contributor

Attempts to solve #2

@PaperNick
Copy link
Contributor Author

Hey @philgyford, that's my attempt to solve this issue.

I'm not sure about the accuracy of the helper functions is_empty_form and is_form_persisted. Do you know about any built-in methods which do something similar?

@philgyford
Copy link
Owner

Thanks!

I'm pretty sure I'm making a pig's ear of making some edits to this (I'm not used to handling PRs, sorry) and have made some tweaks on the https://github.com/philgyford/django-nested-inline-formsets-example/tree/PaperNick-fix/add-validation-when-inserting-nested-inlines-in-empty-parent-form branch.

I've mainly added lots of comments to help explain what's going on to others. And also because I find it hard to follow form logic at the best of times. I also made some of the code slightly more verbose because I find it hard to parse lines like return form.is_valid() and not form.cleaned_data in one go. Hopefully my explanatory comments are correct?

I don't know of any built-in methods that do similar to your new methods, but I haven't worked with forms for some time. It seemed a bit odd to have a is_empty_form function but only use it as not is_empty_form()... but I couldn't think what a concise name for its opposite meaning would be!

@PaperNick
Copy link
Contributor Author

Thanks for the edits! Your comments are completely fine. I cherry-picked your commit and pushed it here.

About the is_empty_form, you have a point but I couldn't think of any other name as well.

@PaperNick
Copy link
Contributor Author

By the way, if you want to make more edits to my PR, you can push directly in my branch.

@philgyford philgyford merged commit 1b5fb03 into philgyford:master Mar 2, 2019
@philgyford
Copy link
Owner

Thanks for all of that!

Years of usually being the only developer on a project, or the only one on particular parts of the code, mean my skills at handling PRs are lacking!

@PaperNick
Copy link
Contributor Author

Thank you as well! Because of your repository, I was able to quickly understand the logic behind the nested inline formsets and get my job done. Your explanatory comments were a huge 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

Successfully merging this pull request may close these issues.

2 participants