PersonEmploymentCrud   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 1
c 5
b 2
f 1
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A custom_queryset() 0 3 1
1
from crudbuilder.abstract import BaseCrudBuilder
2
from crudbuilder.formset import BaseInlineFormset
3
4
from example.models import Person, PersonEmployment
5
from example.tables import CustomPersonTable
6
from example.forms import (
7
    PersonEmployementCreateForm,
8
    PersonEmployementUpdateForm
9
)
10
11
12
class PersonEmploymentInlineFormset(BaseInlineFormset):
13
    inline_model = PersonEmployment
14
    parent_model = Person
15
    exclude = ['created_by', 'updated_by']
16
17
18
class PersonCrud(BaseCrudBuilder):
19
    model = Person
20
    search_fields = ['name']
21
    tables2_fields = ('name', 'email')
22
    tables2_css_class = "table table-bordered table-condensed"
23
    tables2_pagination = 10  # default is 10
24
    modelform_excludes = ['created_by', 'updated_by']
25
    login_required = True
26
    permission_required = True
27
    # custom_table2 = CustomPersonTable
28
29
    # detailview_excludes = ['img']
30
    # inlineformset = PersonEmploymentInlineFormset
31
32
    # custom_templates = {
33
    #     'list': 'yourtemplates/template.html'
34
    # }
35
36
    # permissions = {
37
    #     'list': 'example.person_list',
38
    #     'create': 'example.person_create'
39
    # }
40
41
    # @classmethod
42
    # def custom_queryset(cls, request, **kwargs):
43
    #     return cls.model.objects.filter(created_by=request.user)
44
45
46
class AnotherPersonCrud(BaseCrudBuilder):
47
    model = Person
48
    tables2_css_class = "table table-bordered table-condensed"
49
    custom_postfix_url = 'another-person-crud'  # /appname/<custom_postfix_url>
50
51
52
class PersonEmploymentCrud(BaseCrudBuilder):
53
    model = PersonEmployment
54
    tables2_fields = ('year', 'salary', 'medical_allowance')
55
    search_fields = ['year', 'person__name']
56
    tables2_css_class = "table table-bordered table-condensed"
57
    # custom_modelform = PersonEmploymentForm
58
    # modelform_excludes = ['person']
59
    createupdate_forms = {
60
        'create': PersonEmployementCreateForm,
61
        'update': PersonEmployementUpdateForm
62
    }
63
64
    @classmethod
65
    def custom_queryset(cls, request, **kwargs):
66
        return cls.model.objects.filter(medical_allowance=False)
67