# Path: tests/djangotest/chidiya/serializers.py
# class BasicTestSerializer(HedwigModelSerializer):
#     class Meta:
#         model = BasicTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#         )
# 
# class HiddenTestSerializer(HedwigModelSerializer):
#     class Meta:
#         model = HiddenTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#         )
# 
# class ForeignKeyTestSerializer(HedwigModelSerializer):
#     basic = BasicTestSerializer()
# 
#     class Meta:
#         model = ForeignKeyTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#             'basic',
#         )
# 
#     def create(self, validated_data, **kwargs):
#         basic_data = validated_data.pop('basic', None)
#         if basic_data is None:
#             raise serializers.ValidationError("Basic chahiye")
#         basic = None
#         print basic_data
#         if 'id' in basic_data:
#             try:
#                 basic = BasicTest.objects.get(id=basic_data.get('id'))
#             except models.ObjectDoesNotExist as e:
#                 pass
#         if basic is None:
#             basic_serializer = BasicTestSerializer(data=basic_data)
#             basic_serializer.is_valid()
#             basic = basic_serializer.save()
# 
#         return ForeignKeyTest.objects.create(
#             basic=basic,
#             char=validated_data.get('char'),
#             int=validated_data.get('int'),
#             nullable=validated_data.get('nullable'),
#             date=validated_data.get('date')
#         )
# 
# class ManyToManyTestSerializer(serializers.ModelSerializer):
#     basic_id = serializers.PrimaryKeyRelatedField(queryset=BasicTest.objects.all())
# 
#     class Meta:
#         model = ManyToManyTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#             'basic',
#             'basic_id'
#         )
# 
#         depth = 1
# 
#     def save(self, **kwargs):
#         self.validated_data.pop('basic_id', None)
#         return super(ManyToManyTestSerializer, self).save(**kwargs)
# 
# Path: tests/djangotest/chidiya/models.py
# class BasicTest(BaseTest):
# 
#     def natural_key(self):
#         return self.char, self.int, self.nullable, self.date
# 
# class HiddenTest(BaseTest):
#     class Hedwig:
#         fields = False
# 
# class ForeignKeyTest(BaseTest):
#     class Hedwig:
#         fields = ('char', 'int', 'basic',)
#     basic = models.ForeignKey(BasicTest)
# 
# class ManyToManyTest(BaseTest):
#     basic = models.ManyToManyField(BasicTest)
#     uuid = models.UUIDField()
#     url = models.URLField()


from .serializers import BasicTestSerializer, HiddenTestSerializer, ForeignKeyTestSerializer, ManyToManyTestSerializer
from .models import BasicTest, HiddenTest, ForeignKeyTest, ManyToManyTest
from rest_framework.viewsets import ModelViewSet


class BasicTestViewSet(ModelViewSet):
    queryset = BasicTest.objects.all()
    serializer_class = BasicTestSerializer


class HiddenTestViewSet(ModelViewSet):
    queryset = HiddenTest.objects.all()

# Path: tests/djangotest/chidiya/serializers.py
# class BasicTestSerializer(HedwigModelSerializer):
#     class Meta:
#         model = BasicTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#         )
# 
# class HiddenTestSerializer(HedwigModelSerializer):
#     class Meta:
#         model = HiddenTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#         )
# 
# class ForeignKeyTestSerializer(HedwigModelSerializer):
#     basic = BasicTestSerializer()
# 
#     class Meta:
#         model = ForeignKeyTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#             'basic',
#         )
# 
#     def create(self, validated_data, **kwargs):
#         basic_data = validated_data.pop('basic', None)
#         if basic_data is None:
#             raise serializers.ValidationError("Basic chahiye")
#         basic = None
#         print basic_data
#         if 'id' in basic_data:
#             try:
#                 basic = BasicTest.objects.get(id=basic_data.get('id'))
#             except models.ObjectDoesNotExist as e:
#                 pass
#         if basic is None:
#             basic_serializer = BasicTestSerializer(data=basic_data)
#             basic_serializer.is_valid()
#             basic = basic_serializer.save()
# 
#         return ForeignKeyTest.objects.create(
#             basic=basic,
#             char=validated_data.get('char'),
#             int=validated_data.get('int'),
#             nullable=validated_data.get('nullable'),
#             date=validated_data.get('date')
#         )
# 
# class ManyToManyTestSerializer(serializers.ModelSerializer):
#     basic_id = serializers.PrimaryKeyRelatedField(queryset=BasicTest.objects.all())
# 
#     class Meta:
#         model = ManyToManyTest
#         fields = (
#             'id',
#             'char',
#             'int',
#             'nullable',
#             'date',
#             'basic',
#             'basic_id'
#         )
# 
#         depth = 1
# 
#     def save(self, **kwargs):
#         self.validated_data.pop('basic_id', None)
#         return super(ManyToManyTestSerializer, self).save(**kwargs)
# 
# Path: tests/djangotest/chidiya/models.py
# class BasicTest(BaseTest):
# 
#     def natural_key(self):
#         return self.char, self.int, self.nullable, self.date
# 
# class HiddenTest(BaseTest):
#     class Hedwig:
#         fields = False
# 
# class ForeignKeyTest(BaseTest):
#     class Hedwig:
#         fields = ('char', 'int', 'basic',)
#     basic = models.ForeignKey(BasicTest)
# 
# class ManyToManyTest(BaseTest):
#     basic = models.ManyToManyField(BasicTest)
#     uuid = models.UUIDField()
#     url = models.URLField()


# Path: tests/djangotest/chidiya/views.py
from .serializers import BasicTestSerializer, HiddenTestSerializer, ForeignKeyTestSerializer, ManyToManyTestSerializer
from .models import BasicTest, HiddenTest, ForeignKeyTest, ManyToManyTest
from rest_framework.viewsets import ModelViewSet



class BasicTestViewSet(ModelViewSet):
    queryset = BasicTest.objects.all()
    serializer_class = BasicTestSerializer


class HiddenTestViewSet(ModelViewSet):
    queryset = HiddenTest.objects.all()

    serializer_class = HiddenTestSerializer