-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadmin.py
133 lines (123 loc) · 3.88 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from django.contrib import admin, messages
from .models import *
# Register your models here.
#class ProjectInLine(admin.TabularInline): //pour afficher les champs horizantalement
#class ProjectInLine(admin.StackedInline): //pour afficher les champs verticalement
class ProjectInLine(admin.StackedInline):
model=Projet
class StudentAdmin(admin.ModelAdmin):
list_display =(
'first_name',
'last_name'
)
#Organisation
fields =(
( 'first_name','last_name'),
'email'
)
#Recherche
search_fields =['last_name','first_name']
inlines = [ProjectInLine]
#@admin.register(Coach)
class CoachAdmin(admin.ModelAdmin):
list_display =(
'first_name',
'last_name'
)
#Organisation
fields =(
( 'first_name','last_name'),
'email'
)
#Recherche
search_fields =['last_name','first_name']
#filtrer par rapport au durée
class ProjectDurationFilter(admin.SimpleListFilter):
parameter_name="dure"
title = "Durée"
def lookups(self,request, model_admin):
return (
('1 Month','less than 1 month'),
('3 Months','less than 3 month'),
('4 Months','More than 3 month'),
)
def queryset(self,request, queryset):
if self.value() == "1 Month":
return queryset.filter(dure__lte=30)
if self.value() == "3 Months":
return queryset.filter(dure__gt=30,dure__lte=90)
if self.value() == "4 Months":
return queryset.filter(dure__gt=90)
#Modifier les projets non valide en des projets valide
def set_Valid (model_admin, request, queryset):
rows = queryset.update(isValid=True)
if rows == 1:
msg = "1 project was"
else:
msg = f"{rows} projects were"
messages.success(request,message =f"{msg} successfully marked as valid")
set_Valid.short_description = "Validate"
#Modifier les projets valide en des projets non valide
def set_inValid (model_admin, request, queryset):
number = queryset.filter(isValid=False)
if number.count()> 0:
messages.error(request, "Projects already set to Not Valid")
else :
rows = queryset.update(isValid=False)
if rows == 1:
msg = "1 project was"
else:
msg = f"{rows} projects were"
messages.error(request,message =f"{msg} successfully marked as inValid")
set_inValid.short_description = "inValidate"
class ProjetAdmin(admin.ModelAdmin):
actions =[set_Valid,set_inValid]
actions_on_bottom = True
actions_on_top = True
list_filter = (
'creator',
'isValid',
ProjectDurationFilter
)
list_display =(
'project_name',
'dure',
'supervisor',
'isValid'
)
fieldsets= [
(
'State', #'State' : pour ajouter un titre / None : pour n'ajouter pas un titre
{
'fields':('isValid',)
}
),
(
'About',
{
'fields':(
'project_name',
('creator','supervisor'),
'besoin',
'description'
)
}
),
(
'Durations',
{
'classes': ('collapse',), #pour le choix d'afficher ou de cacher
'fields':(
'dure',
'temp_allocated'
)
}
)
]
#radio_fields = {'supervisor': admin.VERTICAL} #pour afficher la liste des superviseur sous forme de radioButton
autocomplete_fields= ['supervisor'] #admet un recherche de superviseur selon la liste trouver
empty_value_display = '-empty-' #dans les champs vide il affiche "empty"
admin.site.register(Student,StudentAdmin)
admin.site.register(Coach,CoachAdmin)
admin.site.register(Projet,ProjetAdmin)
admin.site.register(MemberShip)