Improve indexing admin interface
This commit is contained in:
@@ -1,21 +1,29 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from mptt.admin import MPTTModelAdmin
|
|
||||||
|
|
||||||
from .models import Index, IndexInstanceNode, IndexTemplateNode
|
from .models import Index, IndexInstanceNode, IndexTemplateNode
|
||||||
|
|
||||||
|
|
||||||
class IndexTemplateNodeAdmin(MPTTModelAdmin):
|
class IndexTemplateNodeInline(admin.StackedInline):
|
||||||
|
extra = 0
|
||||||
list_display = ('expression', 'enabled', 'link_documents')
|
list_display = ('expression', 'enabled', 'link_documents')
|
||||||
|
model = IndexTemplateNode
|
||||||
|
|
||||||
|
|
||||||
class IndexInstanceNodeAdmin(MPTTModelAdmin):
|
class IndexAdmin(admin.ModelAdmin):
|
||||||
model = IndexInstanceNode
|
filter_horizontal = ('document_types',)
|
||||||
list_display = ('value',)
|
inlines = [IndexTemplateNodeInline]
|
||||||
|
list_display = ('name', 'title', 'enabled', 'get_document_types')
|
||||||
|
|
||||||
|
def get_document_types(self, instance):
|
||||||
|
return ', '.join(['"{0}"'.format(document_type) for document_type in instance.document_types.all()]) or _('None')
|
||||||
|
|
||||||
|
get_document_types.short_description = _('Document types')
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Index, IndexAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Index)
|
|
||||||
admin.site.register(IndexTemplateNode, IndexTemplateNodeAdmin)
|
|
||||||
admin.site.register(IndexInstanceNode, IndexInstanceNodeAdmin)
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||||
|
|
||||||
from mptt.fields import TreeForeignKey
|
from mptt.fields import TreeForeignKey
|
||||||
from mptt.models import MPTTModel
|
from mptt.models import MPTTModel
|
||||||
@@ -68,6 +68,9 @@ class IndexTemplateNode(MPTTModel):
|
|||||||
link_documents = models.BooleanField(default=False, verbose_name=_('Link documents'), help_text=_('Check this option to have this node act as a container for documents and not as a parent for further nodes.'))
|
link_documents = models.BooleanField(default=False, verbose_name=_('Link documents'), help_text=_('Check this option to have this node act as a container for documents and not as a parent for further nodes.'))
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
if self.is_root_node():
|
||||||
|
return ugettext('<%s Root>') % self.index
|
||||||
|
else:
|
||||||
return self.expression
|
return self.expression
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
Reference in New Issue
Block a user