Coincidentally, I debated this with myself this afternoon. At the end, i put my notify_by_email method in models.py because I didn't need the request object and it kinda "felt at home" there. However, I'd have put it in my view if I needed the request object so personally, it depends on use case.
Sent from my Windows Phone From: Marc Aymerich Sent: 6/19/2013 7:13 PM To: django-users@googlegroups.com Subject: Sending emails, models or views? Yep, I'm more or less convinced that the logic needed for sending an email should go into models. But what about the action (method call) of sending the email? what layer should be responsible for triggering an email notification? models or views? This is something I keep wondering myself for a long time ... for example, imagine we have a simple Ticket model with two methods, update() and notify_owner() class Ticket(models.Model): def update(self): self.updated_on = now() self.save() def notify_owner(self, msg): send_mail(self.owner, msg) now we want to notify the owner each time a Ticket is updated, shall we include a self.notify_owner('updated!') call on the update() method, so we make sure of that? or maybe it is better to do this on the view each time ticket.update() is called? There are some pros and cons, In the views we have access to the request object which some times is handy because we need some request info to include on the mail. Including the call into the model we make sure that each time we will send an email notification and DRY is good, but is this behavior correct? maybe we only want to notify under certain circumstances... So anyone has thought about this? any rule of thumb? maybe it totally depends on the use case? does this question even make sense? :) Thanks for your answers! -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.