userRestrictedModule.py 935 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1 2
from django.db import models
from rest_framework import serializers
3
from base_app.models import User
4 5 6 7 8
from backend_app.models.abstract.my_model import (
    MyModel,
    MyModelSerializer,
    MyModelViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
9 10


11
class UserRestrictedModule(MyModel):
12 13
    """
    """
14

Florent Chehab's avatar
Florent Chehab committed
15
    # RGPD made easy with CASCADE
16
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
Florent Chehab's avatar
Florent Chehab committed
17

18 19 20 21 22 23
    # User is anonymised
    is_anonymous = models.BooleanField(default=True)

    # To be seen by others than the user, is public needs to be set to True
    is_public = models.BooleanField(default=False)

Florent Chehab's avatar
Florent Chehab committed
24 25 26 27
    class Meta:
        abstract = True


28
class UserRestrictedModuleSerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
29
    owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
Florent Chehab's avatar
Florent Chehab committed
30 31 32

    class Meta:
        model = UserRestrictedModule
33
        fields = "__all__"
34 35 36 37


class UserRestrictedModuleViewSet(MyModelViewSet):
    serializer_class = UserRestrictedModuleSerializer