-
Notifications
You must be signed in to change notification settings - Fork 586
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
Automatically generate django forms #35
Comments
|
Note: hypothesis-django is now a (experimental and unfinished) thing. Many models can be automatically generated. Forms are not yet supported but should be entirely doable. |
|
@DRMacIver is the issue is still open and if it is please eleborate it more specifically.I want to contribute in it. |
|
Yes, it's still open, but I'm worried that we might have different ideas of what will be involved - the However! If you're open to working on other issues, #162 could use your help to move the |
Automate updating of changelog and version in releasing
|
I can confirm (IIRC thanks to @vidyarani-dg) that |
|
Hi! I've used models.py as a template and produced a functioning forms.py, I haven't built out any documentation or augmented the django toystore example, but I will happily finish that out if my approach seems sane and acceptable. |
|
Awesome! You're definitely on the right track, and I'd love to get this in. However - I'd like to get #1695 done first so we can start with the API we want to keep. Would you mind just holding off on this until next week? Once I'm home from my camping trip I'll be able to give a better review too 😄 |
|
Sure thing! I mainly wrote it because I wanted to use it, so I can keep using and polishing in my own project until the scheduled work is done. |
|
OK! We now have #1743 (awaiting review), and I have time for some quick feedback on your draft 😄
|
|
#1743 has been merged, so we're ready for a PR when you are 🎉 |
|
I can probably work on it this weekend. |
|
Regarding your second point, I'm using the form wrapper to allow for other keyword arguments to be passed when instantiating the form, and to package up form = MyFormClass(data=results, my_special_parameter=some_object)(here I'm not seeing how to do that with This is important to support since form instances have the fields (as opposed to models where the class owns the fields), and the other keyword arguments can affect what fields are present in the instance (or how those fields are validated). |
|
first draft using the new hotness. The few tests that I had written against the old draft seem to be running correctly against the new. I'll work on the internal testing for this next. |
|
I'll save detailed feedback for when you open a PR - soon please! You're definitely on the right track and WIPs are welcome 😄. As to the instance/field/kwarg question: Why not require a Form instance be passed to This would look like |
|
I thought about receiving an unbound form instance, but that doesn't quite work either. The unbound form instance has the fields, but you still have to instantiate a new bound form instance (with the
I suppose the class could be introspected from the passed instance, but getting all of its kwargs right for instantiation of the bound form would be troublesome and unreliable. I don't see any alternative but to accept the form kwargs into def from_form(form, form_kwargs=None, **field_strategies):
form_kwargs = form_kwargs or {}
...I'll open the PR once I have some tests in place. |
|
Oh, right. The explicit argument is better, yeah. |
Django models and forms have more than enough metadata for us to automatically introspect them and figure out how to build one. We should have a hypothesis-extra package to do this.
The text was updated successfully, but these errors were encountered: