Ticket #15995: admin.py

File admin.py, 798 bytes (added by Florian Apolloner, 14 years ago)
Line 
1from django.contrib import admin
2
3from .models import Post
4
5class PostAdmin(admin.ModelAdmin):
6 prepopulated_fields = {'slug': ('title',)}
7
8 fieldsets = (
9 (None, {'fields': (('title', 'slug'), 'text')}),
10 ('Publishing options', {'fields': (('public', 'author'),
11 ('pub_date', 'last_updated'))})
12 )
13
14 list_display = ('title',)
15
16 def save_model(self, request, obj, form, change):
17 if not change and not form.cleaned_data.get('author'):
18 obj.author = request.user
19 obj.save()
20
21 def get_form(self, request, obj=None, **kwargs):
22 form = super(PostAdmin, self).get_form(request, obj, **kwargs)
23 form.base_fields['author'].required = False
24 return form
25
26admin.site.register(Post, PostAdmin)
Back to Top