Tag Archives: Tips

Tip: Return True for Model Hooks

Everyone loves before_create and before_save. Recently it came in very handy for logging hits to objects. If the user is logged in, I want to store the user’s full name and the user’s type, otherwise, keep those null. So I added this to my PostHit model:
 
def before_create
if self.user
self.user_name = […]