-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.py
39 lines (32 loc) · 1.35 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
import datetime
from django.db import models
from django.contrib import admin
from django.forms import CheckboxSelectMultiple
from collation.models import Project
from collation.forms import CollationProjectForm
class ProjectAdmin(admin.ModelAdmin):
form = CollationProjectForm
formfield_overrides = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple, 'help_text': 'Select all users who need access.'}
}
def save_model(self, request, obj, form, change):
if obj.version_number is None:
obj.version_number = 1
else:
obj.version_number += 1
if obj.id is not None:
# then we are editing
if hasattr(request.user, 'full_name') and request.user.full_name != '':
obj.last_modified_by = request.user.full_name
else:
obj.last_modified_by = request.user.username
obj.last_modified_time = datetime.datetime.now()
else:
# this is being created
if hasattr(request.user, 'full_name') and request.user.full_name != '':
obj.created_by = request.user.full_name
else:
obj.created_by = request.user.username
obj.created_time = datetime.datetime.now()
super().save_model(request, obj, form, change)
admin.site.register(Project, ProjectAdmin)