2020-12-29 16:19:59 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
from ..models import Comment
|
2021-01-01 23:25:23 +00:00
|
|
|
from common.drf.fields import ReadableHiddenField
|
2020-12-29 16:19:59 +00:00
|
|
|
|
|
|
|
__all__ = ['CommentSerializer']
|
|
|
|
|
|
|
|
|
|
|
|
class CurrentTicket(object):
|
|
|
|
ticket = None
|
|
|
|
|
|
|
|
def set_context(self, serializer_field):
|
|
|
|
self.ticket = serializer_field.context['ticket']
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
return self.ticket
|
|
|
|
|
|
|
|
|
|
|
|
class CommentSerializer(serializers.ModelSerializer):
|
|
|
|
ticket = ReadableHiddenField(default=CurrentTicket())
|
|
|
|
user = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Comment
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_mini = ['id']
|
|
|
|
fields_small = fields_mini + [
|
|
|
|
'body', 'user_display',
|
|
|
|
'date_created', 'date_updated'
|
2020-12-29 16:19:59 +00:00
|
|
|
]
|
2021-08-25 11:02:50 +00:00
|
|
|
fields_fk = ['ticket', 'user', ]
|
2021-04-29 11:10:45 +00:00
|
|
|
fields = fields_small + fields_fk
|
2020-12-29 16:19:59 +00:00
|
|
|
read_only_fields = [
|
|
|
|
'user_display', 'date_created', 'date_updated'
|
|
|
|
]
|