From cbcb8a84c5dbd3da8c762ecb5e42db5cbf380d69 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 3 Aug 2018 18:52:53 -0400 Subject: [PATCH] Add natural key support to the user mailer model. Signed-off-by: Roberto Rosario --- mayan/apps/mailer/managers.py | 8 ++++++++ mayan/apps/mailer/models.py | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 mayan/apps/mailer/managers.py diff --git a/mayan/apps/mailer/managers.py b/mayan/apps/mailer/managers.py new file mode 100644 index 0000000000..4933885211 --- /dev/null +++ b/mayan/apps/mailer/managers.py @@ -0,0 +1,8 @@ +from __future__ import unicode_literals + +from django.db import models + + +class UserMailerManager(models.Manager): + def get_by_natural_key(self, label): + return self.get(label=label) diff --git a/mayan/apps/mailer/models.py b/mayan/apps/mailer/models.py index c186bade64..d51fac223d 100644 --- a/mayan/apps/mailer/models.py +++ b/mayan/apps/mailer/models.py @@ -11,6 +11,7 @@ from django.utils.html import strip_tags from django.utils.module_loading import import_string from django.utils.translation import ugettext_lazy as _ +from .managers import UserMailerManager from .utils import split_recipient_list logger = logging.getLogger(__name__) @@ -51,6 +52,8 @@ class UserMailer(models.Model): blank=True, verbose_name=_('Backend data') ) + objects = UserMailerManager() + class Meta: ordering = ('label',) verbose_name = _('User mailer') @@ -77,6 +80,9 @@ class UserMailer(models.Model): def loads(self): return json.loads(self.backend_data) + def natural_key(self): + return (self.label,) + def save(self, *args, **kwargs): if self.default: UserMailer.objects.select_for_update().exclude(pk=self.pk).update(