Add natural keys to the document type model

This commit is contained in:
Roberto Rosario
2012-10-05 01:13:30 -04:00
parent b231810aaf
commit d849190dbd
2 changed files with 12 additions and 1 deletions

View File

@@ -47,3 +47,8 @@ class RecentDocumentManager(models.Manager):
return document_model.objects.filter(recentdocument__user=user).order_by('-recentdocument__datetime_accessed')
else:
return document_model.objects.none()
class DocumentTypeManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)

View File

@@ -32,7 +32,8 @@ from converter.literals import (DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION,
from .conf.settings import (CHECKSUM_FUNCTION, UUID_FUNCTION,
STORAGE_BACKEND, DISPLAY_SIZE, CACHE_PATH,
ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL)
from .managers import DocumentPageTransformationManager, RecentDocumentManager
from .managers import (DocumentPageTransformationManager, RecentDocumentManager,
DocumentTypeManager)
from .utils import document_save_to_temp_dir
from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES,
VERSION_UPDATE_MAJOR, VERSION_UPDATE_MINOR, VERSION_UPDATE_MICRO)
@@ -60,9 +61,14 @@ class DocumentType(models.Model):
"""
name = models.CharField(max_length=32, verbose_name=_(u'name'), unique=True)
objects = DocumentTypeManager()
def __unicode__(self):
return self.name
def natural_key(self):
return (self.name,)
class Meta:
verbose_name = _(u'document type')
verbose_name_plural = _(u'documents types')