-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathadmin.py
31 lines (24 loc) · 1.09 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
from django.contrib import admin
from models import Question, Topic
class TopicAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug':('name',)}
class QuestionAdmin(admin.ModelAdmin):
list_display = ['text', 'sort_order', 'created_by', 'created_on',
'updated_by', 'updated_on', 'status']
list_editable = ['sort_order', 'status']
raw_id_fields = ['created_by', 'updated_by']
def save_model(self, request, obj, form, change):
'''
Update created-by / modified-by fields.
The date fields are upadated at the model layer, but that's not got
access to the user.
'''
# If the object's new update the created_by field.
if not change:
obj.created_by = request.user
# Either way update the updated_by field.
obj.updated_by = request.user
# Let the superclass do the final saving.
return super(QuestionAdmin, self).save_model(request, obj, form, change)
admin.site.register(Question, QuestionAdmin)
admin.site.register(Topic, TopicAdmin)