#16891: Delete/update should return number of rows modified
-------------------------------------+-------------------------------------
Reporter: estebistec | Owner:
Type: New feature | estebistec
Component: Database layer | Status: new
(models, ORM) | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by akaariai):
An idea for the save() patch: return UPDATED, INSERTED, or None instead of
1/0. You could still do if obj.save(): (matches both UPDATED and INSERTED)
but if need be, you could see if the object was indeed updated or
inserted. The value would be the "outermost" value for multitable
inherited models.
I wonder if it would be a good idea to return the amount of deletions per
object type when deleting? I see at least three choices:
- Just a dict model_class -> delete count, for example in your test case
this would be {R:1, S:2, T:2}
- Tuple total_objects_deleted, abovementioned dict: Example: (5, {R:1,
S:2, T:2})
- Tuple amount_of_outer_objs, abovementioned dict: Example: (1, {R:1,
S:2, T:2})
To me it seems these could be useful, especially the #2 format. This
information can be gotten nearly for free. The inconvenience here is that
you can't do if obj.delete(): as (0, {}) isn't False. Maybe this could be
postponed for later inclusion with kwarg with_counts=True or something. Or
maybe there is just no use case for this.
--
Ticket URL: <https://code.djangoproject.com/ticket/16891#comment:4>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.