Add natural key to the Index model
This commit is contained in:
8
apps/document_indexing/managers.py
Normal file
8
apps/document_indexing/managers.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class IndexManager(models.Manager):
|
||||||
|
def get_by_natural_key(self, name):
|
||||||
|
return self.get(name=name)
|
||||||
@@ -9,6 +9,7 @@ from mptt.fields import TreeForeignKey
|
|||||||
from documents.models import Document, DocumentType
|
from documents.models import Document, DocumentType
|
||||||
|
|
||||||
from .conf.settings import AVAILABLE_INDEXING_FUNCTIONS
|
from .conf.settings import AVAILABLE_INDEXING_FUNCTIONS
|
||||||
|
from .managers import IndexManager
|
||||||
|
|
||||||
available_indexing_functions_string = (_(u'Available functions: %s') % u','.join([u'%s()' % name for name, function in AVAILABLE_INDEXING_FUNCTIONS.items()])) if AVAILABLE_INDEXING_FUNCTIONS else u''
|
available_indexing_functions_string = (_(u'Available functions: %s') % u','.join([u'%s()' % name for name, function in AVAILABLE_INDEXING_FUNCTIONS.items()])) if AVAILABLE_INDEXING_FUNCTIONS else u''
|
||||||
|
|
||||||
@@ -19,6 +20,8 @@ class Index(models.Model):
|
|||||||
enabled = models.BooleanField(default=True, verbose_name=_(u'enabled'), help_text=_(u'Causes this index to be visible and updated when document data changes.'))
|
enabled = models.BooleanField(default=True, verbose_name=_(u'enabled'), help_text=_(u'Causes this index to be visible and updated when document data changes.'))
|
||||||
document_types = models.ManyToManyField(DocumentType, verbose_name=_(u'document types'))
|
document_types = models.ManyToManyField(DocumentType, verbose_name=_(u'document types'))
|
||||||
|
|
||||||
|
objects = IndexManager()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def template_root(self):
|
def template_root(self):
|
||||||
return self.indextemplatenode_set.get(parent=None)
|
return self.indextemplatenode_set.get(parent=None)
|
||||||
@@ -47,6 +50,9 @@ class Index(models.Model):
|
|||||||
def get_document_types_names(self):
|
def get_document_types_names(self):
|
||||||
return u', '.join([unicode(document_type) for document_type in self.document_types.all()] or [u'All'])
|
return u', '.join([unicode(document_type) for document_type in self.document_types.all()] or [u'All'])
|
||||||
|
|
||||||
|
def natural_key(self):
|
||||||
|
return (self.name,)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _(u'index')
|
verbose_name = _(u'index')
|
||||||
verbose_name_plural = _(u'indexes')
|
verbose_name_plural = _(u'indexes')
|
||||||
|
|||||||
Reference in New Issue
Block a user