# Path: tests/patterns_app/models.py
# class CustomAttachment(models.Model):
#     name = models.CharField(max_length=10)
#     parent = models.ForeignKey(
#         CustomPatternModel, models.CASCADE, related_name='attachments',
#     )
# 
# class CustomTypedAttachment(models.Model):
#     name = models.CharField(max_length=10, null=True, blank=True)
#     value = models.FloatField(null=True, blank=True)
#     type = models.ForeignKey(CustomType, models.CASCADE)
#     parent = models.ForeignKey(
#         CustomTypedPatternModel,
#         models.CASCADE,
#         related_name='attachments'
#     )
# 
# class Entity(models.Model):
#     campaign = models.ForeignKey(Campaign, models.CASCADE)
# 
#     class Meta:
#         verbose_name_plural = 'entities'
# 
# class Value(models.Model):
#     attribute = models.ForeignKey(Attribute, models.CASCADE)
#     entity = models.ForeignKey(Entity, models.CASCADE, related_name='values')


from wq.db.patterns import serializers as patterns
from .models import (
    CustomAttachment, CustomTypedAttachment,
    Entity, Value
    )
class CustomAttachmentSerializer(patterns.AttachmentSerializer):
    class Meta(patterns.AttachmentSerializer.Meta):
        model = CustomAttachment
        exclude = ['parent']

        object_field = 'parent'


class CustomPatternSerializer(patterns.AttachedModelSerializer):
    attachments = CustomAttachmentSerializer(many=True)


class CustomTypedAttachmentSerializer(patterns.TypedAttachmentSerializer):
    class Meta(patterns.TypedAttachmentSerializer.Meta):
        model = CustomTypedAttachment
        exclude = ['parent']

        object_field = 'parent'


class CustomTypedPatternSerializer(patterns.AttachedModelSerializer):
    attachments = CustomTypedAttachmentSerializer(many=True)


class ValueSerializerBase(patterns.TypedAttachmentSerializer):
    class Meta(patterns.TypedAttachmentSerializer.Meta):
        model = Value
        exclude = ('entity',)
        object_field = 'entity'
        type_field = 'attribute'

# Path: tests/patterns_app/models.py
# class CustomAttachment(models.Model):
#     name = models.CharField(max_length=10)
#     parent = models.ForeignKey(
#         CustomPatternModel, models.CASCADE, related_name='attachments',
#     )
# 
# class CustomTypedAttachment(models.Model):
#     name = models.CharField(max_length=10, null=True, blank=True)
#     value = models.FloatField(null=True, blank=True)
#     type = models.ForeignKey(CustomType, models.CASCADE)
#     parent = models.ForeignKey(
#         CustomTypedPatternModel,
#         models.CASCADE,
#         related_name='attachments'
#     )
# 
# class Entity(models.Model):
#     campaign = models.ForeignKey(Campaign, models.CASCADE)
# 
#     class Meta:
#         verbose_name_plural = 'entities'
# 
# class Value(models.Model):
#     attribute = models.ForeignKey(Attribute, models.CASCADE)
#     entity = models.ForeignKey(Entity, models.CASCADE, related_name='values')


# Path: tests/patterns_app/serializers.py
from wq.db.patterns import serializers as patterns
from .models import (
    CustomAttachment, CustomTypedAttachment,
    Entity, Value
    )

class CustomAttachmentSerializer(patterns.AttachmentSerializer):
    class Meta(patterns.AttachmentSerializer.Meta):
        model = CustomAttachment
        exclude = ['parent']

        object_field = 'parent'


class CustomPatternSerializer(patterns.AttachedModelSerializer):
    attachments = CustomAttachmentSerializer(many=True)


class CustomTypedAttachmentSerializer(patterns.TypedAttachmentSerializer):
    class Meta(patterns.TypedAttachmentSerializer.Meta):
        model = CustomTypedAttachment
        exclude = ['parent']

        object_field = 'parent'


class CustomTypedPatternSerializer(patterns.AttachedModelSerializer):
    attachments = CustomTypedAttachmentSerializer(many=True)


class ValueSerializerBase(patterns.TypedAttachmentSerializer):
    class Meta(patterns.TypedAttachmentSerializer.Meta):
        model = Value
        exclude = ('entity',)
        object_field = 'entity'
        type_field = 'attribute'

        type_filter = {}