Opened 3 years ago

Closed 20 months ago

Last modified 20 months ago

#16965 closed Bug (fixed)

Model Formsets can_delete documentation lacking actual use example

Reported by: gregcorey@… Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords: can_delete, documentation, model formset
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Formsets can_delete online documentation provides no example of how to utilize this parameter to actually delete a form.

Something along the lines of:

for form in formset.deleted_forms:
    form.cleaned_data['id'].delete() 

is all that is needed (if that is indeed the correct way to do it - I don't know because there is no documentation that I could find :) ).

Thanks.

Attachments (1)

16965.diff (1.6 KB) - added by timo 20 months ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 3 years ago by yasar11732

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I think it's because there is no general way of saving or deleting a form. On the other hand, your example looks completely wrong to me because, form.cleaned_data['id'] would return an int object, an int object doesn't have a delete() method. But for model formsets, there might be a quick way to demonstrate this feature, as they might define a quick way to delete an object.

comment:2 Changed 3 years ago by geraldcor

  • Summary changed from Formsets can_delete documentation lacking actual use example to Model Formsets can_delete documentation lacking actual use example

You are correct. This is for model formsets. That is the use case that should be pretty standard. We want to delete that particular model instance - that is the whole point of the modelform / modelformset feature. So that is why I think it should be better documented (I was actually surprised that form.cleaned_data['id'] returned a model instance ripe for deleting)

I have changed the bug title to reflect Model Formsets as the area requiring documentation.

comment:3 Changed 3 years ago by yasar11732

In this case, it is better to wait for a core developer to explain actual usage example of this feature. After than, I can submit a patch about this.

comment:4 Changed 3 years ago by geraldcor

  • Keywords model formset added; formsets removed

comment:5 Changed 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

I just discussed this with Julien, and we don't really know how this feature is supposed to be used. It really needs documentation.

Version 0, edited 3 years ago by aaugustin (next)

comment:6 follow-up: Changed 3 years ago by amanjeev

Formsets can_delete online documentation provides no example of how to utilize this parameter to actually delete a form

When you say "actually delete a form", you mean delete the object that, that particular form relates to, correct?

I just want to make sure that we are not deleting a form from the front-end end. Rather, this is a feature that is used to delete the object.

comment:7 in reply to: ↑ 6 Changed 3 years ago by geraldcor

Replying to amanjeev:

Formsets can_delete online documentation provides no example of how to utilize this parameter to actually delete a form

When you say "actually delete a form", you mean delete the object that, that particular form relates to, correct?

I just want to make sure that we are not deleting a form from the front-end end. Rather, this is a feature that is used to delete the object.

Yes that is correct. It is the object that the model_formset represents. I apologize for the hastiness of the bug.

Last edited 3 years ago by geraldcor (previous) (diff)

Changed 20 months ago by timo

comment:8 Changed 20 months ago by timo

  • Has patch set

comment:9 Changed 20 months ago by timo

I'm not sure there's a need to document a usage example as ModelFormSet automatically deletes instances for deleted_forms when you call formset.save(). I've added a patch which explains this.

comment:10 Changed 20 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 660c30ed953667b44bdec7058dafe10e0a8ce402:

Fixed #16965 -- Clarified Formset can_delete docs.

Thanks gregcorey@ for the suggestion.

comment:11 Changed 20 months ago by Tim Graham <timograham@…>

In 5567dc68e6fc7788cd9451e5fea52396ffaf3675:

[1.5.x] Fixed #16965 -- Clarified Formset can_delete docs.

Thanks gregcorey@ for the suggestion.

Backport of 660c30ed95 from master

comment:12 Changed 20 months ago by geraldcor

Thanks guys! I didn't realize this would become such a long process. :-)

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