summaryrefslogtreecommitdiff
path: root/app/utils/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/utils/widgets.py')
-rw-r--r--app/utils/widgets.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/app/utils/widgets.py b/app/utils/widgets.py
index dc0c4e0..944601e 100644
--- a/app/utils/widgets.py
+++ b/app/utils/widgets.py
@@ -1,10 +1,48 @@
import os
from django import forms
+from django.contrib import admin
from django.contrib.admin.widgets import AdminFileWidget
from django.utils.safestring import mark_safe
+from django.utils.translation import ugettext_lazy as _
from django.conf import settings
+class TagListFilter(admin.SimpleListFilter):
+ # Human-readable title which will be displayed in the
+ # right admin sidebar just above the filter options.
+ title = _('tag')
+
+ # Parameter for the filter that will be used in the URL query.
+ parameter_name = 'tag'
+
+ def lookups(self, request, model_admin):
+ """
+ Returns a list of tuples. The first element in each
+ tuple is the coded value for the option that will
+ appear in the URL query. The second element is the
+ human-readable name for the option that will appear
+ in the right sidebar.
+ """
+ tl = []
+ self.model_to_use = model_admin.model
+ for t in self.model_to_use.tags.all().order_by('name'):
+ tl += (t.name, t.name),
+ return tl
+
+ def queryset(self, request, queryset):
+ """
+ Returns the filtered queryset based on the value
+ provided in the query string and retrievable via
+ `self.value()`.
+ """
+ qs = self.model_to_use.objects.all()
+ try:
+ request.GET['tag']
+ return qs.filter(tags__name=self.value())
+ except:
+ return qs
+
+
def thumbnail(image_path):
absolute_url = os.path.join(settings.IMAGES_URL, image_path[7:])
print(absolute_url)