瀏覽代碼

improve admin page for better management

pull/342/head
Guillaume Vincent 8 年之前
父節點
當前提交
2f5f1321b1
共有 2 個檔案被更改,包括 20 行新增5 行删除
  1. +20
    -3
      api/admin.py
  2. +0
    -2
      lesspass/settings.py

+ 20
- 3
api/admin.py 查看文件

@@ -1,3 +1,4 @@
from api import models
from api.models import PasswordInfo, Entry, LessPassUser

from django import forms
@@ -5,6 +6,7 @@ from django.contrib import admin
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.db.models import Count


class UserCreationForm(forms.ModelForm):
@@ -45,8 +47,8 @@ class LessPassUserAdmin(BaseUserAdmin):
form = UserChangeForm
add_form = UserCreationForm

list_display = ('email', 'is_admin',)
list_filter = ('is_admin',)
list_display = ('email', 'is_admin', 'column_entries_count')
list_filter = ('is_admin', 'is_active')
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Permissions', {'fields': ('is_admin',)}),
@@ -61,8 +63,23 @@ class LessPassUserAdmin(BaseUserAdmin):
ordering = ('email',)
filter_horizontal = ()

def get_queryset(self, request):
return models.LessPassUser.objects.annotate(entries_count=Count('entries'))

admin.site.register(Entry)
def column_entries_count(self, instance):
return instance.entries_count

column_entries_count.short_description = 'Entries count'
column_entries_count.admin_order_field = 'entries_count'


class EntryAdmin(admin.ModelAdmin):
list_display = ('id', 'user',)
search_fields = ('user__email',)
ordering = ('user',)


admin.site.register(Entry, EntryAdmin)
admin.site.register(PasswordInfo)
admin.site.register(LessPassUser, LessPassUserAdmin)
admin.site.unregister(Group)

+ 0
- 2
lesspass/settings.py 查看文件

@@ -123,8 +123,6 @@ REST_FRAMEWORK = {
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',


Loading…
取消
儲存