Exemplo n.º 1
0
class UserActionSerializer(serializers.ModelSerializer):
    user = NestedUserSerializer()
    action = ChoiceFieldSerializer(choices=ACTION_CHOICES)

    class Meta:
        model = UserAction
        fields = ['id', 'time', 'user', 'action', 'message']
Exemplo n.º 2
0
class ObjectChangeSerializer(serializers.ModelSerializer):
    user = NestedUserSerializer(read_only=True)
    content_type = ContentTypeField(read_only=True)
    changed_object = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = ObjectChange
        fields = [
            'id',
            'time',
            'user',
            'user_name',
            'request_id',
            'action',
            'content_type',
            'changed_object',
            'object_data',
        ]

    def get_changed_object(self, obj):
        """
        Serialize a nested representation of the changed object.
        """
        if obj.changed_object is None:
            return None
        serializer = get_serializer_for_model(obj.changed_object,
                                              prefix='Nested')
        if serializer is None:
            return obj.object_repr
        context = {'request': self.context['request']}
        data = serializer(obj.changed_object, context=context).data
        return data
Exemplo n.º 3
0
class RackReservationSerializer(ValidatedModelSerializer):
    rack = NestedRackSerializer()
    user = NestedUserSerializer()
    tenant = NestedTenantSerializer(required=False, allow_null=True)

    class Meta:
        model = RackReservation
        fields = ['id', 'rack', 'units', 'created', 'user', 'tenant', 'description']
Exemplo n.º 4
0
class RackReservationSerializer(serializers.ModelSerializer):
    rack = NestedRackSerializer()
    user = NestedUserSerializer()
    tenant = NestedTenantSerializer()

    class Meta:
        model = RackReservation
        fields = [
            'id', 'rack', 'units', 'created', 'user', 'tenant', 'description'
        ]