python 2.7 - I want to create a notification to django admin -
i want create notification django admin whenever category added in database. admin should click boolean field , publish category.
you override save() method on categry model - here sample basic code...
class category(models.model): def save(self, *args, **kwargs): if not self.pk: #no pk new try: send_mail('subject here', 'here message.', 'from@example.com', ['superuser@mail.com'], fail_silently=true) except: # bit more elaborate here, logging pass else: #do if update or... pass super(category, self).save(*args, **kwargs) t go route, remember import send_mail functionality...
from django.core.mail import send_mail also, super users on fly db - or import settings file - have hardcoded example.
edit: see brandon's comment regarding post_save. better solution, albeit more advanced. if don't want go route, please wrap email logic in try/except block avoid secondary email failing blowing save.
Comments
Post a Comment