basicModule.py 961 Bytes
Newer Older
1
from django.db import models
2
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
Florent Chehab's avatar
Florent Chehab committed
3
from backend.models.tools import JSONField
4
from backend.models.tag.tagged_item_validation import validate_content_against_config
Florent Chehab's avatar
Florent Chehab committed
5
from backend.models.tag.tags_config import USEFULL_LINKS_CONFIG
6
7


8
class BasicModule(MyModelVersionned):
9

10
    comment = models.TextField(blank=True)
Florent Chehab's avatar
Florent Chehab committed
11
    usefull_links = JSONField(default=list)
12

13
14
    class Meta:
        abstract = True
Florent Chehab's avatar
Florent Chehab committed
15
16


17
class BasicModuleSerializer(MyModelVersionnedSerializer):
Florent Chehab's avatar
Florent Chehab committed
18

Florent Chehab's avatar
Florent Chehab committed
19
    def my_validate(self, attrs):
20
        content = {'usefull_links': attrs['usefull_links']}
Florent Chehab's avatar
Florent Chehab committed
21
        config = {'usefull_links': USEFULL_LINKS_CONFIG}
22
23
24
        validate_content_against_config(config, content)
        return attrs

Florent Chehab's avatar
Florent Chehab committed
25
26
    class Meta:
        model = BasicModule
27
        fields = '__all__'
28
29
30
31


class BasicModuleViewSet(MyModelVersionnedViewSet):
    serializer_class = BasicModuleSerializer