Add natural key to the Index model

This commit is contained in:
Roberto Rosario
2012-10-05 03:05:25 -04:00
parent 065bfd9136
commit e7839dc4ca
2 changed files with 14 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ from mptt.fields import TreeForeignKey
from documents.models import Document, DocumentType
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''
@@ -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.'))
document_types = models.ManyToManyField(DocumentType, verbose_name=_(u'document types'))
objects = IndexManager()
@property
def template_root(self):
return self.indextemplatenode_set.get(parent=None)
@@ -47,6 +50,9 @@ class Index(models.Model):
def get_document_types_names(self):
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:
verbose_name = _(u'index')
verbose_name_plural = _(u'indexes')