2021-06-03 15:22:16 +02:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from ee.models.event_definition import EnterpriseEventDefinition
|
|
|
|
from posthog.api.shared import UserBasicSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class EnterpriseEventDefinitionSerializer(serializers.ModelSerializer):
|
2021-06-10 01:45:42 +02:00
|
|
|
updated_by = UserBasicSerializer(read_only=True)
|
2021-06-03 15:22:16 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EnterpriseEventDefinition
|
|
|
|
fields = (
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"owner",
|
|
|
|
"description",
|
|
|
|
"tags",
|
|
|
|
"volume_30_day",
|
|
|
|
"query_usage_30_day",
|
|
|
|
"updated_at",
|
|
|
|
"updated_by",
|
|
|
|
)
|
|
|
|
read_only_fields = ["id", "name", "updated_at", "volume_30_day", "query_usage_30_day"]
|
|
|
|
|
|
|
|
def update(self, event_definition: EnterpriseEventDefinition, validated_data):
|
|
|
|
validated_data["updated_by"] = self.context["request"].user
|
|
|
|
return super().update(event_definition, validated_data)
|
2021-06-10 01:45:42 +02:00
|
|
|
|
|
|
|
def to_representation(self, instance):
|
|
|
|
representation = super().to_representation(instance)
|
|
|
|
representation["owner"] = UserBasicSerializer(instance=instance.owner).data
|
|
|
|
return representation
|