basicModule.py 980 Bytes
Newer Older
1
from django.db import models
2
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
3
from django.contrib.postgres.fields 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)
11
    usefull_links = JSONField(blank=True, 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

19
20
    def validate(self, attrs):
        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