diff --git a/mayan/apps/document_parsing/managers.py b/mayan/apps/document_parsing/managers.py index f5d63bdda3..c435114b41 100644 --- a/mayan/apps/document_parsing/managers.py +++ b/mayan/apps/document_parsing/managers.py @@ -4,6 +4,7 @@ import logging import sys import traceback +from django.apps import apps from django.conf import settings from django.db import models @@ -48,3 +49,16 @@ class DocumentPageContentManager(models.Manager): action_object=document_version.document, target=document_version ) + + +class DocumentTypeSettingsManager(models.Manager): + def get_by_natural_key(self, document_type_natural_key): + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + try: + document_type = DocumentType.objects.get_by_natural_key(document_type_natural_key) + except DocumentType.DoesNotExist: + raise self.model.DoesNotExist + + return self.get(document_type__pk=document_type.pk) diff --git a/mayan/apps/document_parsing/models.py b/mayan/apps/document_parsing/models.py index 30ea3ee81f..c17caf39c1 100644 --- a/mayan/apps/document_parsing/models.py +++ b/mayan/apps/document_parsing/models.py @@ -6,7 +6,7 @@ from django.utils.translation import ugettext_lazy as _ from documents.models import DocumentPage, DocumentType, DocumentVersion -from .managers import DocumentPageContentManager +from .managers import DocumentPageContentManager, DocumentTypeSettingsManager @python_2_unicode_compatible @@ -37,6 +37,12 @@ class DocumentTypeSettings(models.Model): verbose_name=_('Automatically queue newly created documents for parsing.') ) + objects = DocumentTypeSettingsManager() + + def natural_key(self): + return self.document_type.natural_key() + natural_key.dependencies = ['documents.DocumentType'] + class Meta: verbose_name = _('Document type settings') verbose_name_plural = _('Document types settings')