Commit fbe13e6e authored by Florent Chehab's avatar Florent Chehab

moderation handling enhanced

parent 02af4292
Pipeline #26688 passed with stages
in 2 minutes and 48 seconds
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericRelation
from .pendingModeration import PendingModeration
class MyModel(models.Model):
......@@ -17,6 +19,7 @@ class MyModel(models.Model):
updated_on = models.DateTimeField(null=True)
updated_by = models.ForeignKey(
User, null=True, on_delete=models.SET_NULL, related_name='+')
pending_moderation = GenericRelation(PendingModeration)
class Meta:
abstract = True
......@@ -5,6 +5,7 @@ from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from backend.utils import is_member
from .myModel import MyModel
from .pendingModeration import PendingModerationSerializer
class MyModelSerializer(serializers.ModelSerializer):
......@@ -14,6 +15,7 @@ class MyModelSerializer(serializers.ModelSerializer):
format="%Y-%m-%d %H:%M:%S", read_only=True)
moderated_by = serializers.CharField(read_only=True)
updated_by = serializers.CharField(read_only=True)
pending_moderation = PendingModerationSerializer(many=True, read_only=True)
# TODO : updated_by_username useless ? See in rest API
updated_by_username = serializers.SerializerMethodField(read_only=True)
......
......@@ -17,7 +17,7 @@ class MyModelViewSet(DictModeViewSet):
to prefetch some table and enhance performances
"""
self.mymodel_queryset = self.queryset.prefetch_related(
'moderated_by', 'updated_by')
'moderated_by', 'updated_by', 'pending_moderation')
return self.extend_queryset()
def extend_queryset(self):
......
......@@ -21,6 +21,15 @@ class PendingModeration(models.Model):
class PendingModerationSerializer(serializers.ModelSerializer):
content_type = serializers.CharField(read_only=True)
object_id = serializers.CharField(read_only=True)
updated_by = serializers.CharField(read_only=True)
updated_on = serializers.DateTimeField(
format="%Y-%m-%d %H:%M:%S", read_only=True)
new_object = serializers.JSONField(read_only=True)
class Meta:
model = PendingModeration
fields = '__all__'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment