# Path: tests/rest_app/models.py
# class OneToOneModel(LabelModel):
#     root = models.OneToOneField(RootModel, models.CASCADE)
# 
#     wq_label_template = "onetoonemodel for {{root}}"
# 
# class ExtraModel(LabelModel):
#     root = models.ForeignKey(
#         RootModel,
#         models.CASCADE,
#         related_name="extramodels",
#     )
#     alt_root = models.ForeignKey(
#         RootModel,
#         models.CASCADE,
#         related_name="extramodel_set",
#         null=True,
#         blank=True,
#     )
# 
#     wq_label_template = "extramodel for {{root}}"
# 
# class Child(LabelModel):
#     name = models.CharField(max_length=10)
#     parent = models.ForeignKey(Parent, models.CASCADE, related_name="children")
# 
# class ChoiceModel(LabelModel):
#     CHOICE_CHOICES = [
#         ('one', 'Choice One'),
#         ('two', 'Choice Two'),
#         ('three', 'Choice Three'),
#     ]
#     name = models.CharField(
#         max_length=10,
#         help_text='Enter Name',
#     )
#     choice = models.CharField(
#         max_length=10,
#         help_text='Pick One',
#         choices=CHOICE_CHOICES,
#     )
# 
#     wq_label_template = "{{name}}: {{choice}}"
# 
# class DateModel(models.Model):
#     name = models.CharField(max_length=10)
#     date = models.DateTimeField()
#     empty_date = models.DateTimeField(null=True)
# 
#     def __str__(self):
#         return "%s on %s" % (self.name, self.date.date())
# 
# class Item(LabelModel):
#     name = models.CharField(max_length=10)
#     type = models.ForeignKey(ItemType, models.CASCADE)
# 
#     class Meta:
#         ordering = ('type', 'name')
# 
# class ExpensiveModel(LabelModel):
#     name = models.CharField(max_length=20)
#     expensive = ExpensiveField(cost=2, max_length=255)
#     more_expensive = ExpensiveField(
#         cost=5,
#         max_length=255,
#         null=True,
#         blank=True
#     )
# 
# class FieldsetModel(LabelModel):
#     # General
#     name = models.CharField(max_length=50)
#     title = models.CharField(max_length=20)
# 
#     # Address
#     address = models.CharField(max_length=255)
#     city = models.CharField(max_length=255)


from rest_framework import serializers
from wq.db.rest.serializers import ModelSerializer
from .models import (
    OneToOneModel, ExtraModel, Child, ChoiceModel, DateModel, Item,
    ExpensiveModel, FieldsetModel
)


class RootModelSerializer(ModelSerializer):
    extramodels = ModelSerializer.for_model(
        ExtraModel, include_fields="__all__"
    )(many=True)
    onetoonemodel = ModelSerializer.for_model(
        OneToOneModel, include_fields="__all__"
    )()


class ChildSerializer(ModelSerializer):
    class Meta:
        model = Child
        exclude = ('parent',)


class ParentSerializer(ModelSerializer):
    children = ChildSerializer(many=True)


class ItemSerializer(ModelSerializer):
    class Meta:
        wq_field_config = {
            'type': {
                 'filter': {

# Path: tests/rest_app/models.py
# class OneToOneModel(LabelModel):
#     root = models.OneToOneField(RootModel, models.CASCADE)
# 
#     wq_label_template = "onetoonemodel for {{root}}"
# 
# class ExtraModel(LabelModel):
#     root = models.ForeignKey(
#         RootModel,
#         models.CASCADE,
#         related_name="extramodels",
#     )
#     alt_root = models.ForeignKey(
#         RootModel,
#         models.CASCADE,
#         related_name="extramodel_set",
#         null=True,
#         blank=True,
#     )
# 
#     wq_label_template = "extramodel for {{root}}"
# 
# class Child(LabelModel):
#     name = models.CharField(max_length=10)
#     parent = models.ForeignKey(Parent, models.CASCADE, related_name="children")
# 
# class ChoiceModel(LabelModel):
#     CHOICE_CHOICES = [
#         ('one', 'Choice One'),
#         ('two', 'Choice Two'),
#         ('three', 'Choice Three'),
#     ]
#     name = models.CharField(
#         max_length=10,
#         help_text='Enter Name',
#     )
#     choice = models.CharField(
#         max_length=10,
#         help_text='Pick One',
#         choices=CHOICE_CHOICES,
#     )
# 
#     wq_label_template = "{{name}}: {{choice}}"
# 
# class DateModel(models.Model):
#     name = models.CharField(max_length=10)
#     date = models.DateTimeField()
#     empty_date = models.DateTimeField(null=True)
# 
#     def __str__(self):
#         return "%s on %s" % (self.name, self.date.date())
# 
# class Item(LabelModel):
#     name = models.CharField(max_length=10)
#     type = models.ForeignKey(ItemType, models.CASCADE)
# 
#     class Meta:
#         ordering = ('type', 'name')
# 
# class ExpensiveModel(LabelModel):
#     name = models.CharField(max_length=20)
#     expensive = ExpensiveField(cost=2, max_length=255)
#     more_expensive = ExpensiveField(
#         cost=5,
#         max_length=255,
#         null=True,
#         blank=True
#     )
# 
# class FieldsetModel(LabelModel):
#     # General
#     name = models.CharField(max_length=50)
#     title = models.CharField(max_length=20)
# 
#     # Address
#     address = models.CharField(max_length=255)
#     city = models.CharField(max_length=255)


# Path: tests/rest_app/serializers.py
from rest_framework import serializers
from wq.db.rest.serializers import ModelSerializer
from .models import (
    OneToOneModel, ExtraModel, Child, ChoiceModel, DateModel, Item,
    ExpensiveModel, FieldsetModel
)



class RootModelSerializer(ModelSerializer):
    extramodels = ModelSerializer.for_model(
        ExtraModel, include_fields="__all__"
    )(many=True)
    onetoonemodel = ModelSerializer.for_model(
        OneToOneModel, include_fields="__all__"
    )()


class ChildSerializer(ModelSerializer):
    class Meta:
        model = Child
        exclude = ('parent',)


class ParentSerializer(ModelSerializer):
    children = ChildSerializer(many=True)


class ItemSerializer(ModelSerializer):
    class Meta:
        wq_field_config = {
            'type': {
                 'filter': {

                     'active': [