userRestrictedModule.py 944 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
3
from django.db import models
from rest_framework import serializers
from django.contrib.auth.models import User
4
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
Florent Chehab's avatar
Florent Chehab committed
5
6


7
class UserRestrictedModule(MyModel):
Florent Chehab's avatar
Florent Chehab committed
8
    # RGPD made easy with CASCADE
9
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
Florent Chehab's avatar
Florent Chehab committed
10

11
12
13
14
15
16
    # 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
17
18
19
20
    class Meta:
        abstract = True


21
22
class UserRestrictedModuleSerializer(MyModelSerializer):
    owner = serializers.HiddenField(
Florent Chehab's avatar
Florent Chehab committed
23
24
25
26
27
28
        default=serializers.CurrentUserDefault(),
    )  # TODO check that this works

    class Meta:
        model = UserRestrictedModule
        fields = '__all__'
29
30
31
32


class UserRestrictedModuleViewSet(MyModelViewSet):
    serializer_class = UserRestrictedModuleSerializer