Opened 15 years ago

Closed 13 years ago

Last modified 13 years ago

#13021 closed New feature (wontfix)

Allowing models to influence QuerySet.update

Reported by: Dennis Kaarsemaker Owned by: Dennis Kaarsemaker
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: update
Cc: slinkp@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'd like to have a bit more control over what update() does, e.g. for auditing purposes. I know that I can simply write a few lines of code near every update() call to do what I want, but that violates DRY.

Attached patch adds a few new features:

  • pre_update and post_update signals
  • a pre_update method for Field that does nothing
  • a pre_update method for DateField for auto_now magic
  • an update() method for Model that calls pre_update for all fields. This method is a classmethod
  • a patched QuerySet.update() that
    • Sends the pre_update and post_update signals
    • Calls the models update method to update the kwargs dict

The patch is untested, but should give a good idea of what I want to achieve. Is this approach suitable for inclusion in django ? If so, I will complete the patch, add tests and documentation and will submit it for inclusion at the appropriate time.

Attachments (1)

improved_update.patch (3.0 KB ) - added by Dennis Kaarsemaker 15 years ago.

Download all attachments as: .zip

Change History (8)

by Dennis Kaarsemaker, 15 years ago

Attachment: improved_update.patch added

comment:1 by Dennis Kaarsemaker, 15 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedDesign decision needed

comment:2 by Dennis Kaarsemaker, 15 years ago

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Patch has been moved to github, tests and documentation are added as separate commits. See: http://github.com/seveas/django/tree/seveas/ticket13021

comment:3 by Luke Plant, 14 years ago

Type: New feature

comment:4 by Luke Plant, 14 years ago

Severity: Normal

comment:6 by Luke Plant, 13 years ago

Resolution: wontfix
Status: newclosed

For the reasons given by Jacob in that thread, I'm going to WONTFIX this.

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