Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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 Mariusz Felisiak, 5 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization
Version: 2.2master

I think we can even add two more lines to the current example.

comment:2 by Bruno Furtado, 5 years ago

Owner: changed from nobody to Bruno Furtado
Status: newassigned

comment:3 by Bruno Furtado, 5 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.

comment:4 by Carlton Gibson, 5 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.)

in reply to:  4 comment:5 by Mariusz Felisiak, 5 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.)

in reply to:  4 comment:6 by Bruno Furtado, 5 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:7 by Mariusz Felisiak, 5 years ago

Has patch: set

comment:8 by Mariusz Felisiak, 5 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 571ab44:

Fixed #30321 -- Added example of changed_data to forms docs.

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In bfe27929:

[2.2.x] Fixed #30321 -- Added example of changed_data to forms docs.

Backport of 571ab44e8a8936014c22e7eebe4948d9611fd7ce from master

Note: See TracTickets for help on using tickets.
Back to Top