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

3
4
from reversion_compare.admin import CompareVersionAdmin
from shared import get_api_config, get_api_objs
5
6
7

api_config = get_api_config()

8
9
10
11
12
13
14
15
16
17
18
19
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
    ),
)
20
21


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

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

Florent Chehab's avatar
Florent Chehab committed
39
40
41
42
43
44
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))