# Path: users/models.py
# class UserDetail(models.Model):
#     user = models.OneToOneField(User, primary_key=True)
#     longitude = models.FloatField(null=True)
#     latitude = models.FloatField(null=True)
#     token_facebook = models.CharField(null=True, max_length=255)
#     avatar_url = models.URLField(null=True)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def _get_avatar_thumbnail_url(self):
#         return "https://s3.amazonaws.com/walladog/thumbnails/" + self.user.username + ".png"
#     avatar_thumbnail_url = property(_get_avatar_thumbnail_url)
# 
#     def _get_products_count(self):
#         from products.models import Product
#         return Product.objects.filter(seller=self.user.id).filter(active=1).count()
#     products_count = property(_get_products_count)
# 
#     def __unicode__(self):
#         if self.user.first_name or self.user.last_name:
#             return self.user.first_name + " " + self.user.last_name
#         else:
#             return self.user.username
# 
#     def __str__(self):
#         if self.user.first_name or self.user.last_name:
#             return self.user.first_name + " " + self.user.last_name
#         else:
#             return self.user.username


from django.contrib.auth.models import User
from users.models import UserDetail
from rest_framework import serializers

class UserSerializer(serializers.Serializer):

    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')
    email = serializers.EmailField(source='user.email')
    password = serializers.CharField(source='user.password')
    longitude = serializers.FloatField(allow_null=True, default=None)
    latitude = serializers.FloatField(allow_null=True, default=None)
    token_facebook = serializers.CharField(allow_null=True, default=None)
    avatar_url = serializers.URLField(allow_null=True, default=None)

    def create(self, validated_data):


# Path: users/models.py
# class UserDetail(models.Model):
#     user = models.OneToOneField(User, primary_key=True)
#     longitude = models.FloatField(null=True)
#     latitude = models.FloatField(null=True)
#     token_facebook = models.CharField(null=True, max_length=255)
#     avatar_url = models.URLField(null=True)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def _get_avatar_thumbnail_url(self):
#         return "https://s3.amazonaws.com/walladog/thumbnails/" + self.user.username + ".png"
#     avatar_thumbnail_url = property(_get_avatar_thumbnail_url)
# 
#     def _get_products_count(self):
#         from products.models import Product
#         return Product.objects.filter(seller=self.user.id).filter(active=1).count()
#     products_count = property(_get_products_count)
# 
#     def __unicode__(self):
#         if self.user.first_name or self.user.last_name:
#             return self.user.first_name + " " + self.user.last_name
#         else:
#             return self.user.username
# 
#     def __str__(self):
#         if self.user.first_name or self.user.last_name:
#             return self.user.first_name + " " + self.user.last_name
#         else:
#             return self.user.username


# Path: users/serializers.py
from django.contrib.auth.models import User
from users.models import UserDetail
from rest_framework import serializers


class UserSerializer(serializers.Serializer):

    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')
    email = serializers.EmailField(source='user.email')
    password = serializers.CharField(source='user.password')
    longitude = serializers.FloatField(allow_null=True, default=None)
    latitude = serializers.FloatField(allow_null=True, default=None)
    token_facebook = serializers.CharField(allow_null=True, default=None)
    avatar_url = serializers.URLField(allow_null=True, default=None)

    def create(self, validated_data):


        instance = UserDetail()