# Path: dynamic_rest/serializers.py
# class DynamicEphemeralSerializer(
#     WithDynamicSerializerMixin,
#     serializers.Serializer
# ):
# 
#     """DREST-compatible baseclass for non-model serializers."""
# 
#     def to_representation(self, instance):
#         """
#         Provides post processing. Sub-classes should implement their own
#         to_representation method, but pass the resulting dict through
#         this function to get tagging and field selection.
# 
#         Arguments:
#             instance: Serialized dict, or object. If object,
#                 it will be serialized by the super class's
#                 to_representation() method.
#         """
# 
#         if not isinstance(instance, dict):
#             data = super(
#                 DynamicEphemeralSerializer,
#                 self
#             ).to_representation(instance)
#         else:
#             data = instance
#             instance = EphemeralObject(data)
# 
#         if self.id_only():
#             return data
#         else:
#             return tag_dict(data, serializer=self, instance=instance)
# 
# class DynamicModelSerializer(
#     WithDynamicModelSerializerMixin,
#     serializers.ModelSerializer
# ):
# 
#     """DREST-compatible model-based serializer."""
#     pass
# 
# Path: tests/models.py
# class Car(models.Model):
#     name = models.CharField(max_length=60)
#     country = models.ForeignKey(Country, on_delete=models.CASCADE)
# 
# class Cat(models.Model):
#     name = models.TextField()
#     home = models.ForeignKey('Location', on_delete=models.CASCADE)
#     backup_home = models.ForeignKey(
#         'Location',
#         related_name='friendly_cats',
#         on_delete=models.CASCADE
#     )
#     hunting_grounds = models.ManyToManyField(
#         'Location',
#         related_name='annoying_cats',
#         related_query_name='getoffmylawn'
#     )
#     parent = models.ForeignKey(
#         'Cat',
#         null=True,
#         blank=True,
#         related_name='kittens',
#         on_delete=models.CASCADE
#     )
# 
# class Country(models.Model):
#     name = models.CharField(max_length=60)
#     short_name = models.CharField(max_length=30)
# 
# class Dog(models.Model):
#     name = models.TextField()
#     fur_color = models.TextField()
#     origin = models.TextField()
# 
# class Group(models.Model):
#     name = models.TextField(unique=True)
#     permissions = models.ManyToManyField('Permission', related_name='groups')
# 
# class Horse(models.Model):
#     name = models.TextField()
#     origin = models.TextField()
# 
# class Location(models.Model):
#     name = models.TextField()
#     blob = models.TextField()
# 
# class Part(models.Model):
#     car = models.ForeignKey(Car, on_delete=models.CASCADE)
#     name = models.CharField(max_length=60)
#     country = models.ForeignKey(Country, on_delete=models.CASCADE)
# 
# class Permission(models.Model):
#     name = models.TextField()
#     code = models.IntegerField()
# 
# class Profile(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     display_name = models.TextField()
#     thumbnail_url = models.TextField(null=True, blank=True)
# 
# class User(models.Model):
#     name = models.TextField()
#     last_name = models.TextField()
#     groups = models.ManyToManyField('Group', related_name='users')
#     permissions = models.ManyToManyField('Permission', related_name='users')
#     date_of_birth = models.DateField(null=True, blank=True)
#     # 'related_name' intentionally left unset in location field below:
#     location = models.ForeignKey(
#         'Location',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_type = models.ForeignKey(
#         ContentType,
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_id = models.TextField(null=True, blank=True)
#     favorite_pet = GenericForeignKey(
#         'favorite_pet_type',
#         'favorite_pet_id',
#     )
#     is_dead = models.BooleanField(null=True, default=False)
# 
# class Zebra(models.Model):
#     name = models.TextField()
#     origin = models.TextField()


from rest_framework.serializers import CharField
from dynamic_rest.fields import (
    CountField,
    DynamicField,
    DynamicGenericRelationField,
    DynamicMethodField,
    DynamicRelationField
)
from dynamic_rest.serializers import (
    DynamicEphemeralSerializer,
    DynamicModelSerializer
)
from tests.models import (
    Car,
    Cat,
    Country,
    Dog,
    Group,
    Horse,
    Location,
    Part,
    Permission,
    Profile,
    User,
    Zebra,
)
            'id',
            'name',
            'origin',
        )


class ZebraSerializer(DynamicModelSerializer):

    class Meta:
        model = Zebra
        name = 'zebra'
        fields = (
            'id',
            'name',
            'origin',
        )


class CountrySerializer(DynamicModelSerializer):

    class Meta:
        model = Country
        fields = ('id', 'name', 'short_name')
        deferred_fields = ('name', 'short_name')


class PartSerializer(DynamicModelSerializer):
    country = DynamicRelationField('CountrySerializer')

    class Meta:

# Path: dynamic_rest/serializers.py
# class DynamicEphemeralSerializer(
#     WithDynamicSerializerMixin,
#     serializers.Serializer
# ):
# 
#     """DREST-compatible baseclass for non-model serializers."""
# 
#     def to_representation(self, instance):
#         """
#         Provides post processing. Sub-classes should implement their own
#         to_representation method, but pass the resulting dict through
#         this function to get tagging and field selection.
# 
#         Arguments:
#             instance: Serialized dict, or object. If object,
#                 it will be serialized by the super class's
#                 to_representation() method.
#         """
# 
#         if not isinstance(instance, dict):
#             data = super(
#                 DynamicEphemeralSerializer,
#                 self
#             ).to_representation(instance)
#         else:
#             data = instance
#             instance = EphemeralObject(data)
# 
#         if self.id_only():
#             return data
#         else:
#             return tag_dict(data, serializer=self, instance=instance)
# 
# class DynamicModelSerializer(
#     WithDynamicModelSerializerMixin,
#     serializers.ModelSerializer
# ):
# 
#     """DREST-compatible model-based serializer."""
#     pass
# 
# Path: tests/models.py
# class Car(models.Model):
#     name = models.CharField(max_length=60)
#     country = models.ForeignKey(Country, on_delete=models.CASCADE)
# 
# class Cat(models.Model):
#     name = models.TextField()
#     home = models.ForeignKey('Location', on_delete=models.CASCADE)
#     backup_home = models.ForeignKey(
#         'Location',
#         related_name='friendly_cats',
#         on_delete=models.CASCADE
#     )
#     hunting_grounds = models.ManyToManyField(
#         'Location',
#         related_name='annoying_cats',
#         related_query_name='getoffmylawn'
#     )
#     parent = models.ForeignKey(
#         'Cat',
#         null=True,
#         blank=True,
#         related_name='kittens',
#         on_delete=models.CASCADE
#     )
# 
# class Country(models.Model):
#     name = models.CharField(max_length=60)
#     short_name = models.CharField(max_length=30)
# 
# class Dog(models.Model):
#     name = models.TextField()
#     fur_color = models.TextField()
#     origin = models.TextField()
# 
# class Group(models.Model):
#     name = models.TextField(unique=True)
#     permissions = models.ManyToManyField('Permission', related_name='groups')
# 
# class Horse(models.Model):
#     name = models.TextField()
#     origin = models.TextField()
# 
# class Location(models.Model):
#     name = models.TextField()
#     blob = models.TextField()
# 
# class Part(models.Model):
#     car = models.ForeignKey(Car, on_delete=models.CASCADE)
#     name = models.CharField(max_length=60)
#     country = models.ForeignKey(Country, on_delete=models.CASCADE)
# 
# class Permission(models.Model):
#     name = models.TextField()
#     code = models.IntegerField()
# 
# class Profile(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     display_name = models.TextField()
#     thumbnail_url = models.TextField(null=True, blank=True)
# 
# class User(models.Model):
#     name = models.TextField()
#     last_name = models.TextField()
#     groups = models.ManyToManyField('Group', related_name='users')
#     permissions = models.ManyToManyField('Permission', related_name='users')
#     date_of_birth = models.DateField(null=True, blank=True)
#     # 'related_name' intentionally left unset in location field below:
#     location = models.ForeignKey(
#         'Location',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_type = models.ForeignKey(
#         ContentType,
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_id = models.TextField(null=True, blank=True)
#     favorite_pet = GenericForeignKey(
#         'favorite_pet_type',
#         'favorite_pet_id',
#     )
#     is_dead = models.BooleanField(null=True, default=False)
# 
# class Zebra(models.Model):
#     name = models.TextField()
#     origin = models.TextField()


# Path: tests/serializers.py
from rest_framework.serializers import CharField
from dynamic_rest.fields import (
    CountField,
    DynamicField,
    DynamicGenericRelationField,
    DynamicMethodField,
    DynamicRelationField
)
from dynamic_rest.serializers import (
    DynamicEphemeralSerializer,
    DynamicModelSerializer
)
from tests.models import (
    Car,
    Cat,
    Country,
    Dog,
    Group,
    Horse,
    Location,
    Part,
    Permission,
    Profile,
    User,
    Zebra,
)

            'id',
            'name',
            'origin',
        )


class ZebraSerializer(DynamicModelSerializer):

    class Meta:
        model = Zebra
        name = 'zebra'
        fields = (
            'id',
            'name',
            'origin',
        )


class CountrySerializer(DynamicModelSerializer):

    class Meta:
        model = Country
        fields = ('id', 'name', 'short_name')
        deferred_fields = ('name', 'short_name')


class PartSerializer(DynamicModelSerializer):
    country = DynamicRelationField('CountrySerializer')

    class Meta:

        model = Part