Login

Tag "hooks"

Snippet List

Model Hooks

Runs model methods on save, create, update, delete Similar to Rails hooks **Usage:** *in models.py* from myproject.hooks import connect_hooks class MyModel(models.Model): #... # only on first save of a newly created object def before_create(self): print self def after_create(self): print self # not on first save of a newly created object def before_update(self): print self def after_update(self): print self # any save, new object or update def before_save(self): print self def after_save(self): print self # delete, self is still available after delete def before_delete(self): print self def after_delete(self): print self **connect_hooks(MyModel)**

  • model
  • hooks
Read More

Multiple Delete in Admin

This snippet demonstrates the use of the SpecialOps patch ( [link here](http://hackermojo.com/mt-static/archives/2008/02/django-special-ops.html) )to the django 0.96 admin. Once you have the patch, adding actions like these is simple. You can use the @admin_action decorator on model and manager methods to expose them inside the admin. For manager methods, the method should accept a list of IDs. For model methods, only self should be required.

  • admin
  • multiple
  • delete
  • hooks
Read More

2 snippets posted so far.