-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
from django.contrib import admin | ||
from .models import UpFile | ||
from models import UpFile | ||
import os | ||
|
||
class PathFilter(admin.SimpleListFilter): | ||
# Human-readable title which will be displayed in the | ||
# right admin sidebar just above the filter options. | ||
title = 'id' | ||
|
||
# Parameter for the filter that will be used in the URL query. | ||
parameter_name = 'path' | ||
|
||
def lookups(self, request, model_admin): | ||
qs = model_admin.get_queryset(request) | ||
|
||
ret = [(b, b) for b in set((os.path.dirname(a) if os.path.dirname(a) != '' else a) for a in qs.values_list('path', flat=True))] | ||
print(ret) | ||
return ret | ||
|
||
def queryset(self, request, queryset): | ||
# Compare the requested value (either '80s' or '90s') | ||
# to decide how to filter the queryset. | ||
if self.value() is not None: | ||
print(self.value()) | ||
return queryset.filter(path__startswith=self.value(),) | ||
|
||
class UpFileAdmin(admin.ModelAdmin): | ||
fieldsets = [ | ||
(None, {'fields':['path', 'status', 'user']}), | ||
('Upload date infomation', {'fields':['up_date'], 'classes':['collapse']}), | ||
] | ||
admin.site.register(UpFile) | ||
list_display = ('path', 'label') | ||
list_editable = ('label',) | ||
list_filter = ('user', PathFilter) | ||
|
||
admin.site.register(UpFile, UpFileAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters