admin.py 1.22 KB
Newer Older
1
2
from django.contrib import admin

3
from reversion_compare.admin import CompareVersionAdmin
4
from shared import get_api_objs
5

6
7
8
9
10
11
12
13
14
15
16
17
VERSIONNED_MODELS = map(
    lambda obj: obj.Model,
    get_api_objs(
        has_model=True, ignore_in_admin=False, versionned=True, requires_testing=False
    ),
)
CLASSIC_MODELS = map(
    lambda obj: obj.Model,
    get_api_objs(
        has_model=True, ignore_in_admin=False, versionned=False, requires_testing=False
    ),
)
18
19


Florent Chehab's avatar
Florent Chehab committed
20
#######
21
# Register the models and perform some dynamic checks
Florent Chehab's avatar
Florent Chehab committed
22
#######
23

Florent Chehab's avatar
Florent Chehab committed
24
25
26
for Model in CLASSIC_MODELS:
    # Register the model in the admin in a standard way
    admin.site.register(Model)
27
    try:
Florent Chehab's avatar
Florent Chehab committed
28
29
        # Check that it doesn't have the get_serializer method
        Model.get_serializer()
30
31
32
33
        raise Exception(
            "A 'CLASSIC MODEL' SHOULDN'T have the "
            "get_serializer method, {}".format(Model)
        )
34
35
36
    except AttributeError:
        pass

Florent Chehab's avatar
Florent Chehab committed
37
38
39
40
41
42
for Model in VERSIONNED_MODELS:
    # Register the model in the admin with versioning
    admin.site.register(Model, CompareVersionAdmin)
    # Check that it has a get_serializer method
    if Model.get_serializer().Meta.model != Model:
        raise Exception("Get_serializer configuration incorrect in", str(Model))