forked from django-de/2010.djangocon.eu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.py
33 lines (27 loc) · 1.01 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
from django.contrib import admin
from blog.models import Post
class BlogPostAdmin(admin.ModelAdmin):
list_display = ('author', 'draft', 'title', 'publish_date',)
list_filter = ('author', 'draft',)
list_display_links = ('title',)
date_hierarchy = 'publish_date'
fieldsets = (
('Metadata', {
'fields': ('title', 'slug', 'draft', 'publish_date')
}),
('Authorship', {
'classes': ('collapse',),
'fields': ('author', 'modified_date', 'created_date',),
}),
('Body', {
'fields': ('body_markdown',),
}),
)
readonly_fields = ('modified_date', 'created_date',)
prepopulated_fields = {'slug': ('title',)}
def formfield_for_foreignkey(self, dbfield, request, **kwargs):
ff = super(BlogPostAdmin, self).formfield_for_foreignkey(dbfield, request, **kwargs)
if dbfield.name == 'author':
ff.initial = request.user
return ff
admin.site.register(Post, BlogPostAdmin)