#30321 closed Cleanup/optimization (fixed)
Add example to Form.changed_data
Reported by: | Matthew Pava | Owned by: | Bruno Furtado |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
https://docs.djangoproject.com/en/2.2/ref/forms/api/#django.forms.Form.changed_data
The documentation has a nice example for Form.has_changed()
that shows the result as True
or False
. I would like to see another such simple example in the documentation for Form.changed_data
that actually shows what the results of Form.changed_data
are.
Change History (10)
comment:1 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
Version: | 2.2 → master |
comment:2 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 6 years ago
Do you think that just add the output from the snippet is enough?
>>> f = ContactForm(request.POST, initial=data) >>> if f.has_changed(): ... print("The following fields changed: %s" % ", ".join(f.changed_data)) The following fields changed: subject, message
Or something like this is better?
>>> f = ContactForm(request.POST, initial=data) >>> if f.has_changed(): >>> print(f.changed_data) ['subject', 'message']
Let me know so I can submit a patch for it. Thank you.
follow-ups: 5 6 comment:4 by , 6 years ago
Hi Bruno. From Mariusz' comment, it looks like he intends that you just add the extra lines:
I guess:
>>> f.changed_data ['subject', 'message']
Easiest way forward is if you open a PR. (It's better to comment on actual code.)
comment:5 by , 6 years ago
Yeah, exactly 👍.
Replying to Carlton Gibson:
Hi Bruno. From Mariusz' comment, it looks like he intends that you just add the extra lines:
I guess:
>>> f.changed_data ['subject', 'message']Easiest way forward is if you open a PR. (It's better to comment on actual code.)
comment:6 by , 6 years ago
Hi Carlton,
Thank you for clarify it. I agree, I opened the PR let's keep discussing there then.: https://github.com/django/django/pull/11186
Replying to Carlton Gibson:
Hi Bruno. From Mariusz' comment, it looks like he intends that you just add the extra lines:
I guess:
>>> f.changed_data ['subject', 'message']Easiest way forward is if you open a PR. (It's better to comment on actual code.)
comment:8 by , 6 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I think we can even add two more lines to the current example.