1
|
|
|
from crudbuilder.abstract import BaseCrudBuilder |
2
|
|
|
from example.models import Person, PersonEmployment |
3
|
|
|
from example.forms import( |
4
|
|
|
PersonEmployementCreateForm, |
5
|
|
|
PersonEmployementUpdateForm |
6
|
|
|
) |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class PersonCrud(BaseCrudBuilder): |
10
|
|
|
model = Person |
11
|
|
|
search_feilds = ['name'] |
12
|
|
|
tables2_fields = ('name', 'email') |
13
|
|
|
tables2_css_class = "table table-bordered table-condensed" |
14
|
|
|
tables2_pagination = 20 # default is 10 |
15
|
|
|
modelform_excludes = ['created_by', 'updated_by'] |
16
|
|
|
login_required = True |
17
|
|
|
permission_required = True |
18
|
|
|
|
19
|
|
|
# custom_templates = { |
20
|
|
|
# 'list': 'yourtemplates/template.html' |
21
|
|
|
# } |
22
|
|
|
|
23
|
|
|
# permissions = { |
24
|
|
|
# 'list': 'example.person_list', |
25
|
|
|
# 'create': 'example.person_create' |
26
|
|
|
# } |
27
|
|
|
|
28
|
|
|
def custom_queryset(self, request, **kwargs): |
29
|
|
|
return self.model.objects.all() |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class PersonEmploymentCrud(BaseCrudBuilder): |
33
|
|
|
model = PersonEmployment |
34
|
|
|
tables2_fields = ('year', 'salary', 'medical_allowance') |
35
|
|
|
search_feilds = ['year', 'person__name'] |
36
|
|
|
tables2_css_class = "table table-bordered table-condensed" |
37
|
|
|
# custom_modelform = PersonEmploymentForm |
38
|
|
|
# modelform_excludes = ['person'] |
39
|
|
|
createupdate_forms = { |
40
|
|
|
'create': PersonEmployementCreateForm, |
41
|
|
|
'update': PersonEmployementUpdateForm |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
def custom_queryset(self, request, **kwargs): |
45
|
|
|
return self.model.objects.filter(medical_allowance=False) |
46
|
|
|
|