# Path: images/serializers.py
# class ImageSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = Image
#         fields = ('id', 'name', 'photo_url', 'photo_thumbnail_url')
# 
# Path: products/models.py
# class Product(models.Model):
#     name = models.CharField(max_length=30)
#     race = models.ForeignKey(Race, null=True, related_name='race')
#     seller = models.ForeignKey(UserDetail, null=False)
#     gender = models.CharField(max_length=3, choices=GENDERS, default='NON')
#     sterile = models.BooleanField(default=False)
#     description = models.CharField(max_length=250, default='')
#     state = models.ForeignKey(State, null=True, default=1)
#     price = models.FloatField(null=False, default=0)
#     category = models.ForeignKey(Category)
#     active = models.BooleanField(null=False, default=True)
#     location = models.PointField(null=False)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def _get_latitude(self):
#         return str(self.location.y)
#     latitude = property(_get_latitude)
# 
#     def _get_longitude(self):
#         return str(self.location.x)
#     longitude = property(_get_longitude)
# 
#     def _get_race_id(self):
#         return str(self.race.id)
#     raceid = property(_get_race_id)
# 
#     def _get_state_id(self):
#         return str(self.state.id)
#     stateid = property(_get_state_id)
# 
#     def _get_category_id(self):
#         return str(self.category.id)
#     categoryid = property(_get_category_id)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: users/serializers.py
# class UserPublicListSerializer(serializers.ModelSerializer):
#     id = serializers.ReadOnlyField(source='user.id')
#     first_name = serializers.CharField(allow_null=True, source='user.first_name', default='')
#     last_name = serializers.CharField(allow_null=True, source='user.last_name', default='')
#     username = serializers.CharField(source='user.username')
# 
#     class Meta:
#         model = UserDetail
#         fields = ('id', 'first_name', 'last_name', 'username', 'avatar_url', 'avatar_thumbnail_url', 'products_count')


from rest_framework import serializers
from images.serializers import ImageSerializer
from products.models import Product
from users.serializers import UserPublicListSerializer



class ProductsSerializer(serializers.ModelSerializer):

    class Meta:
        model = Product
        fields = ('id', 'name', 'race', 'gender', 'sterile', 'description', 'state', 'price', 'category',
                  'active', 'created_at')

class ProductsListSerializer(serializers.ModelSerializer):

    race = serializers.StringRelatedField()
    state = serializers.StringRelatedField()
    category = serializers.StringRelatedField()
    images = ImageSerializer(many=True)

# Path: images/serializers.py
# class ImageSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = Image
#         fields = ('id', 'name', 'photo_url', 'photo_thumbnail_url')
# 
# Path: products/models.py
# class Product(models.Model):
#     name = models.CharField(max_length=30)
#     race = models.ForeignKey(Race, null=True, related_name='race')
#     seller = models.ForeignKey(UserDetail, null=False)
#     gender = models.CharField(max_length=3, choices=GENDERS, default='NON')
#     sterile = models.BooleanField(default=False)
#     description = models.CharField(max_length=250, default='')
#     state = models.ForeignKey(State, null=True, default=1)
#     price = models.FloatField(null=False, default=0)
#     category = models.ForeignKey(Category)
#     active = models.BooleanField(null=False, default=True)
#     location = models.PointField(null=False)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def _get_latitude(self):
#         return str(self.location.y)
#     latitude = property(_get_latitude)
# 
#     def _get_longitude(self):
#         return str(self.location.x)
#     longitude = property(_get_longitude)
# 
#     def _get_race_id(self):
#         return str(self.race.id)
#     raceid = property(_get_race_id)
# 
#     def _get_state_id(self):
#         return str(self.state.id)
#     stateid = property(_get_state_id)
# 
#     def _get_category_id(self):
#         return str(self.category.id)
#     categoryid = property(_get_category_id)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: users/serializers.py
# class UserPublicListSerializer(serializers.ModelSerializer):
#     id = serializers.ReadOnlyField(source='user.id')
#     first_name = serializers.CharField(allow_null=True, source='user.first_name', default='')
#     last_name = serializers.CharField(allow_null=True, source='user.last_name', default='')
#     username = serializers.CharField(source='user.username')
# 
#     class Meta:
#         model = UserDetail
#         fields = ('id', 'first_name', 'last_name', 'username', 'avatar_url', 'avatar_thumbnail_url', 'products_count')


# Path: products/serializers.py
from rest_framework import serializers
from images.serializers import ImageSerializer
from products.models import Product
from users.serializers import UserPublicListSerializer




class ProductsSerializer(serializers.ModelSerializer):

    class Meta:
        model = Product
        fields = ('id', 'name', 'race', 'gender', 'sterile', 'description', 'state', 'price', 'category',
                  'active', 'created_at')

class ProductsListSerializer(serializers.ModelSerializer):

    race = serializers.StringRelatedField()
    state = serializers.StringRelatedField()
    category = serializers.StringRelatedField()
    images = ImageSerializer(many=True)

    seller = UserPublicListSerializer()