#27280: can_order/can_delete documentation examples don't require initial data
-------------------------------------+-------------------------------------
     Reporter:  Kifsif               |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  Documentation        |                  Version:  1.10
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Kifsif):

 Replying to [comment:5 Tim Graham]:
 > Check the output of the first part of the example without initial data:
 > {{{
 > for form in formset:
 > ...     print(form.as_table())
 > }}}
 > Only 1 blank form appears.


 Hm. I'm starting to understand you.

 This in your opinion is the first part of the example:

 {{{
 >>> from django.forms import formset_factory
 >>> from myapp.forms import ArticleForm
 >>> ArticleFormSet = formset_factory(ArticleForm, can_delete=True)
 >>> formset = ArticleFormSet(initial=[
 ...     {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)},
 ...     {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)},
 ... ])
 >>> for form in formset:
 ...     print(form.as_table())
 }}}


 And this is the second:


 {{{
 >>> data = {
 ...     'form-TOTAL_FORMS': '3',
 ...     'form-INITIAL_FORMS': '2',
 ...     'form-MAX_NUM_FORMS': '',
 ...     'form-0-title': 'Article #1',
 ...     'form-0-pub_date': '2008-05-10',
 ...     'form-0-DELETE': 'on',
 ...     'form-1-title': 'Article #2',
 ...     'form-1-pub_date': '2008-05-11',
 ...     'form-1-DELETE': '',
 ...     'form-2-title': '',
 ...     'form-2-pub_date': '',
 ...     'form-2-DELETE': '',
 ... }

 >>> formset = ArticleFormSet(data, initial=[
 ...     {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)},
 ...     {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)},
 ... ])
 >>> [form.cleaned_data for form in formset.deleted_forms]
 }}}


 So what? What about the first part if the second part overriddes it
 completely.
 Well. The first part is ok. I didn't mention it in the ticket.

 The second part is erroneous. Because it provides initial data and doesn't
 make use of them. This is exactly what I mean: it misleads the user as
 s/he may think initial data is necessary here.

--
Ticket URL: <https://code.djangoproject.com/ticket/27280#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.898c83711f33735f76030cdd69e91610%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to