mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Prettied-up the admin
This commit is contained in:
		| @@ -4,6 +4,8 @@ Changelog | |||||||
| * 0.0.4 | * 0.0.4 | ||||||
|  |  | ||||||
|   * Added automated tagging basted on keyword matching |   * Added automated tagging basted on keyword matching | ||||||
|  |   * Cleaned up the document listing page | ||||||
|  |   * Removed ``User`` and ``Group`` from the admin | ||||||
|  |  | ||||||
| * 0.0.3 | * 0.0.3 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,15 +1,42 @@ | |||||||
| from django.contrib import admin | from django.contrib import admin | ||||||
|  | from django.contrib.auth.models import User, Group | ||||||
| from django.core.urlresolvers import reverse | from django.core.urlresolvers import reverse | ||||||
| from django.templatetags.static import static | from django.templatetags.static import static | ||||||
|  |  | ||||||
| from .models import Sender, Tag, Document | from .models import Sender, Tag, Document | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class MonthListFilter(admin.SimpleListFilter): | ||||||
|  |  | ||||||
|  |     title = "Month" | ||||||
|  |  | ||||||
|  |     # Parameter for the filter that will be used in the URL query. | ||||||
|  |     parameter_name = "month" | ||||||
|  |  | ||||||
|  |     def lookups(self, request, model_admin): | ||||||
|  |         r = [] | ||||||
|  |         for document in Document.objects.all(): | ||||||
|  |             r.append(( | ||||||
|  |                 document.created.strftime("%Y-%m"), | ||||||
|  |                 document.created.strftime("%B %Y") | ||||||
|  |             )) | ||||||
|  |         return sorted(set(r), key=lambda x: x[0], reverse=True) | ||||||
|  |  | ||||||
|  |     def queryset(self, request, queryset): | ||||||
|  |  | ||||||
|  |         if not self.value(): | ||||||
|  |             return None | ||||||
|  |  | ||||||
|  |         year, month = self.value().split("-") | ||||||
|  |         return queryset.filter(created__year=year, created__month=month) | ||||||
|  |  | ||||||
|  |  | ||||||
| class DocumentAdmin(admin.ModelAdmin): | class DocumentAdmin(admin.ModelAdmin): | ||||||
|  |  | ||||||
|     search_fields = ("sender__name", "title", "content",) |     search_fields = ("sender__name", "title", "content",) | ||||||
|     list_display = ("edit", "created", "sender", "title", "tags_", "pdf") |     list_display = ("edit", "created", "sender", "title", "tags_", "pdf") | ||||||
|     list_filter = ("created", "tags", "sender") |     list_filter = (MonthListFilter, "tags", "sender") | ||||||
|  |     list_editable = ("sender", "title",) | ||||||
|     list_per_page = 25 |     list_per_page = 25 | ||||||
|  |  | ||||||
|     def edit(self, obj): |     def edit(self, obj): | ||||||
| @@ -39,3 +66,7 @@ class DocumentAdmin(admin.ModelAdmin): | |||||||
| admin.site.register(Sender) | admin.site.register(Sender) | ||||||
| admin.site.register(Tag) | admin.site.register(Tag) | ||||||
| admin.site.register(Document, DocumentAdmin) | admin.site.register(Document, DocumentAdmin) | ||||||
|  |  | ||||||
|  | # Unless we implement multi-user, these default registrations don't make sense. | ||||||
|  | admin.site.unregister(Group) | ||||||
|  | admin.site.unregister(User) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn