Skip to content

Commit

Permalink
Add registry package and adjust admin for PyCon TW
Browse files Browse the repository at this point in the history
  • Loading branch information
yychen committed Apr 4, 2020
1 parent 4d75e62 commit e33db03
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# https://www.djangoproject.com/
Django==3.0.3

# A simple, easy access key-value registry for Django
# https://github.com/yychen/dj-registry
dj-registry==0.2

# Reusable mixins for Django
# https://django-braces.readthedocs.io/en/latest/index.html
django-braces==1.14.0
Expand Down
42 changes: 42 additions & 0 deletions src/core/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django.contrib import admin
from django.conf import settings
from django.utils.translation import gettext_lazy as _

from registry.models import Entry
from registry.admin import EntryAdmin


class CurrentConferenceFilter(admin.filters.SimpleListFilter):
title = 'Current Conference'
parameter_name = 'current'

def lookups(self, request, model_admin):
return [
(None, _('Current')),
('other', _('Other')),
('all', _('All')),
]

def queryset(self, request, queryset):
if self.value() == 'all':
return queryset
elif self.value() == 'other':
return queryset.exclude(key__startswith=f'{settings.CONFERENCE_DEFAULT_SLUG}')

return queryset.filter(key__startswith=f'{settings.CONFERENCE_DEFAULT_SLUG}')

def choices(self, changelist):
for lookup, title in self.lookup_choices:
yield {
'selected': self.value() == lookup,
'query_string': changelist.get_query_string({self.parameter_name: lookup}),
'display': title,
}


class PyConEntryAdmin(EntryAdmin):
list_filter = (CurrentConferenceFilter, ) + EntryAdmin.list_filter


admin.site.unregister(Entry)
admin.site.register(Entry, PyConEntryAdmin)
1 change: 1 addition & 0 deletions src/pycontw2016/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
'django_q',
'import_export',
'sorl.thumbnail',
'registry',
)

LOCAL_APPS = (
Expand Down

0 comments on commit e33db03

Please sign in to comment.