Add natural key to the DocumentType model to allow dumping and loading via the bootstrap app

This commit is contained in:
Roberto Rosario
2012-09-22 03:01:33 -04:00
parent d48338a989
commit 47ac12b4d1
2 changed files with 13 additions and 1 deletions

View File

@@ -45,3 +45,8 @@ class RecentDocumentManager(models.Manager):
return document_model.objects.filter(recentdocument__user=user)
else:
return []
class DocumentTypeManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)

View File

@@ -27,7 +27,8 @@ from converter.literals import (DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION,
from mimetype.icons import icon_file_extension_error
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)
@@ -55,11 +56,17 @@ class DocumentType(models.Model):
Define document types or classes to which a specific set of
properties can be attached
"""
# TODO: make unique
name = models.CharField(max_length=32, verbose_name=_(u'name'))
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')