Opened 17 years ago

Closed 17 years ago

#4879 closed (fixed)

post_create signal

Reported by: Alexander Solovyov <alexander.solovyov@…> Owned by: George Vilches
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: sprintsept14
Cc: gav@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Patch adds post_create signal to model's save() method. This signal is useful to interact with newly created objects.

Attachments (7)

post_create_patch.diff (870 bytes ) - added by Alexander Solovyov <alexander.solovyov@…> 17 years ago.
post_create_patch.2.diff (896 bytes ) - added by Alexander Solovyov <alexander.solovyov@…> 17 years ago.
working version
post_create_patch.3.diff (897 bytes ) - added by Alexander Solovyov <alexander.solovyov@…> 17 years ago.
typo fixed
post_save_with_created_kw.patch (1.1 KB ) - added by gav@… 17 years ago.
Adds a "created" flag to the post_save signal.
post_save_with_created_kw_r5991.patch (1.0 KB ) - added by George Vilches <gav@…> 17 years ago.
Updated patch for post_save created signal against r5991.
django_unit_test_model_signals.diff (2.6 KB ) - added by George Vilches <gav@…> 17 years ago.
Unit test for all model signals, including testing the post_save created keyword
post_save_with_created_kw_r6184.patch (3.8 KB ) - added by George Vilches <gav@…> 17 years ago.
Post save patch + unit tests against r6184

Download all attachments as: .zip

Change History (14)

by Alexander Solovyov <alexander.solovyov@…>, 17 years ago

Attachment: post_create_patch.diff added

comment:1 by Malcolm Tredinnick, 17 years ago

Triage Stage: UnreviewedAccepted

There was a general consensus in a recent django-dev thread about this. No core developer spoke against it. The only question is whether to make it a new signal, or a flag attached to the post_save signal (signal emissions are not free). I'll have to rummage through the archives. Marking this as "accepted" though, since it's reasonable.

by Alexander Solovyov <alexander.solovyov@…>, 17 years ago

Attachment: post_create_patch.2.diff added

working version

comment:2 by Alexander Solovyov <alexander.solovyov@…>, 17 years ago

First version does not work if PK value is not set.

by Alexander Solovyov <alexander.solovyov@…>, 17 years ago

Attachment: post_create_patch.3.diff added

typo fixed

by gav@…, 17 years ago

Adds a "created" flag to the post_save signal.

comment:3 by gav@…, 17 years ago

Cc: gav@… added

+1 to mtredinnick's idea for just adding a flag to the post_save signal. The patch I attached does exactly this, and uses a variable that already existed in the save() method that held this information anyway (it was missing one place it needed to be set, so the patch handles that as well), so the additional overhead should be nothing.

by George Vilches <gav@…>, 17 years ago

Updated patch for post_save created signal against r5991.

by George Vilches <gav@…>, 17 years ago

Unit test for all model signals, including testing the post_save created keyword

comment:4 by George Vilches <gav@…>, 17 years ago

The django_unit_test_model_signals.diff includes a unit tests for the Django test suite covering the following signals:

pre_save
post_save
pre_delete
post_delete

It verifies that these signals fire in the proper order, that they have the expected instance of the model, and that the created flag on post_save is correctly set.

As far as I could tell, tests for these signals do not exist anywhere.

comment:5 by George Vilches <gav@…>, 17 years ago

Owner: changed from nobody to George Vilches

I'll take responsibility for cleaning up this ticket for the sprint.

by George Vilches <gav@…>, 17 years ago

Post save patch + unit tests against r6184

comment:6 by George Vilches <gav@…>, 17 years ago

Keywords: sprintsept14 added

comment:7 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [6269]) Fixed #4879 -- Added 'created' arg to post_save signal. This is True is a new object is created. Patch from George Vilches.

Fully backwards compatible, because signal receivers do not have to be able to accept all the arguments (thankyou, robust_apply()).

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