update document admin

This commit is contained in:
jonaswinkler 2021-02-10 18:55:39 +01:00
parent 5aed41223b
commit 252d4cb513

View File

@ -59,16 +59,19 @@ class DocumentAdmin(admin.ModelAdmin):
list_display_links = ("title",) list_display_links = ("title",)
list_display = ( list_display = (
"correspondent",
"title",
"tags_",
"created", "created",
"added",
"archive_serial_number",
"title",
"mime_type",
"filename",
"archive_filename"
) )
list_filter = ( list_filter = (
"document_type", ("mime_type"),
"tags", ("archive_serial_number", admin.EmptyFieldListFilter),
"correspondent" ("archive_filename", admin.EmptyFieldListFilter),
) )
filter_horizontal = ("tags",) filter_horizontal = ("tags",)
@ -99,26 +102,6 @@ class DocumentAdmin(admin.ModelAdmin):
index.add_or_update_document(obj) index.add_or_update_document(obj)
super(DocumentAdmin, self).save_model(request, obj, form, change) super(DocumentAdmin, self).save_model(request, obj, form, change)
@mark_safe
def tags_(self, obj):
r = ""
for tag in obj.tags.all():
r += self._html_tag(
"span",
tag.name + ", "
)
return r
@staticmethod
def _html_tag(kind, inside=None, **kwargs):
attributes = format_html_join(' ', '{}="{}"', kwargs.items())
if inside is not None:
return format_html("<{kind} {attributes}>{inside}</{kind}>",
kind=kind, attributes=attributes, inside=inside)
return format_html("<{} {}/>", kind, attributes)
class RuleInline(admin.TabularInline): class RuleInline(admin.TabularInline):
model = SavedViewFilterRule model = SavedViewFilterRule