Opened 15 years ago
Closed 15 years ago
#13552 closed (fixed)
pre_save & post_save model signals should also specify database to save
| Reported by: | Mandx | Owned by: | Andrew Godwin |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | signals multi-db pre_save post_save | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The pre_save & post_save model signals should also specify on which database the object will be saved. Also, should be possible to connect to model signals on a specific database.
Something like:
from django.db.models.signals import pre_save
from myapp.models import MyModel
def my_default_handler(sender, **kwargs):
# Do something on default db
...
def my_alternate_handler(sender, **kwargs):
# Do something on alternate db
...
pre_save.connect(my_default_handler, sender=MyModel, database='default_db')
pre_save.connect(my_alternate_handler, sender=MyModel, database='alternate_db')
Attachments (3)
Change History (8)
comment:1 by , 15 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 15 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
by , 15 years ago
| Attachment: | 13552-take-1.diff added |
|---|
Patch that adds "using" keyword for *_save, *_delete, m2m_changed
comment:3 by , 15 years ago
| Has patch: | set |
|---|
I've attached a patch that implements a "using" keyword for pre_save, post_save, pre_delete, post_delete, and m2m_changed, along with modified docs and tests.
comment:4 by , 15 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:5 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Weeell, we can't add a param to the connect method, since Signal's don't know about models, or databases, or anything like that. However, the DB should be a param to the actual signal invocation so one can filter out the calls they want.