/
admin.py
54 lines (36 loc) · 1.41 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.admin.sites import NotRegistered
from techblog.models import Article, UserProfile, Category, Language
class ArticleAdmin(admin.ModelAdmin):
save_on_top = True
list_display = ('title', 'get_authors', 'is_public', 'date')
list_editable = ('is_public',)
list_filter = ('authors', 'is_public',)
date_hierarchy = 'date'
def get_authors(self, obj):
return ', '.join(str(author) for author in obj.authors.all())
get_authors.short_description = u'Authors list'
admin.site.register(Article, ArticleAdmin)
class LanguageAdmin(admin.ModelAdmin):
save_on_top = True
prepopulated_fields = {"slug": ("title",)}
admin.site.register(Language, LanguageAdmin)
class CategoryAdmin(admin.ModelAdmin):
save_on_top = True
prepopulated_fields = {"slug": ("title",)}
admin.site.register(Category, CategoryAdmin)
class UserProfileInline(admin.StackedInline):
model = UserProfile
can_delete = False
class UserAdmin(admin.ModelAdmin):
inlines = (UserProfileInline,)
list_display = ('username', 'get_full_name', 'date_joined', 'is_active',)
date_hierarchy = 'date_joined'
list_filter = ('is_active',)
try:
admin.site.unregister(User)
except NotRegistered:
pass
admin.site.register(User, UserAdmin)