userRestrictedModule.py 771 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
3
4
5
6
7
8
9
from django.db import models
from rest_framework import serializers
from django.contrib.auth.models import User


class UserRestrictedModule(models.Model):
    # RGPD made easy with CASCADE
    user = models.ForeignKey(User, on_delete=models.CASCADE)

10
11
12
13
14
15
    # 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
16
17
18
19
20
21
22
23
24
25
26
27
    class Meta:
        abstract = True


class UserRestrictedModuleSerializer(serializers.ModelSerializer):
    user = serializers.HiddenField(
        default=serializers.CurrentUserDefault(),
    )  # TODO check that this works

    class Meta:
        model = UserRestrictedModule
        fields = '__all__'