# Path: yak/rest_social_network/models.py
# class Tag(CoreModel):
#     name = models.CharField(max_length=75, unique=True)
# 
#     class Meta:
#         ordering = ['-created']
# 
#     def identifier(self):
#         return "#{}".format(self.name)
# 
#     def type(self):
#         return "tag"
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# class Comment(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     TAG_FIELD = 'description'
#     related_tags = models.ManyToManyField(Tag, blank=True)
# 
#     description = models.TextField()
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="comments", on_delete=models.CASCADE)
# 
#     class Meta:
#         ordering = ['created']
# 
# class Follow(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="following", on_delete=models.CASCADE)
# 
#     @property
#     def object_type(self):
#         return self.content_type.name
# 
#     @property
#     def name(self):
#         # object must be registered with FollowableModel
#         return self.content_object.identifier()
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
#         ordering = ['created']
# 
# class Flag(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="flags", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# class Share(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
#     shared_with = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='shared_with')
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="shares", on_delete=models.CASCADE)
# 
# class Like(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="likes", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# Path: yak/rest_user/serializers.py
# class UserSerializer(AuthSerializerMixin, YAKModelSerializer):
# 
#     def __new__(cls, *args, **kwargs):
#         """
#         Can't just inherit in the class definition due to lots of import issues
#         """
#         return yak_settings.USER_SERIALIZER(*args, **kwargs)


from django.contrib.auth import get_user_model
from rest_framework import serializers
from yak.rest_social_network.models import Tag, Comment, Follow, Flag, Share, Like
from yak.rest_user.serializers import UserSerializer
                return self.context['request'].user.following.get(content_type=content_type, object_id=obj.pk).pk
            except Follow.DoesNotExist:
                pass
        return None


class TagSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tag
        fields = ('name', 'id')


class CommentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Comment
        exclude = ('related_tags',)

    def __init__(self, *args, **kwargs):
        """
        The `user` field is added here to help with recursive import issues mentioned in rest_user.serializers
        """
        super(CommentSerializer, self).__init__(*args, **kwargs)
        self.fields["user"] = UserSerializer(read_only=True, default=serializers.CurrentUserDefault())


class FollowSerializer(serializers.ModelSerializer):
    follower = UserSerializer(read_only=True, source="user")
    following = serializers.SerializerMethodField('get_user_follow')

    class Meta:

# Path: yak/rest_social_network/models.py
# class Tag(CoreModel):
#     name = models.CharField(max_length=75, unique=True)
# 
#     class Meta:
#         ordering = ['-created']
# 
#     def identifier(self):
#         return "#{}".format(self.name)
# 
#     def type(self):
#         return "tag"
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# class Comment(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     TAG_FIELD = 'description'
#     related_tags = models.ManyToManyField(Tag, blank=True)
# 
#     description = models.TextField()
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="comments", on_delete=models.CASCADE)
# 
#     class Meta:
#         ordering = ['created']
# 
# class Follow(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="following", on_delete=models.CASCADE)
# 
#     @property
#     def object_type(self):
#         return self.content_type.name
# 
#     @property
#     def name(self):
#         # object must be registered with FollowableModel
#         return self.content_object.identifier()
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
#         ordering = ['created']
# 
# class Flag(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="flags", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# class Share(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
#     shared_with = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='shared_with')
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="shares", on_delete=models.CASCADE)
# 
# class Like(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="likes", on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = (("user", "content_type", "object_id"),)
# 
# Path: yak/rest_user/serializers.py
# class UserSerializer(AuthSerializerMixin, YAKModelSerializer):
# 
#     def __new__(cls, *args, **kwargs):
#         """
#         Can't just inherit in the class definition due to lots of import issues
#         """
#         return yak_settings.USER_SERIALIZER(*args, **kwargs)


# Path: yak/rest_social_network/serializers.py
from django.contrib.auth import get_user_model
from rest_framework import serializers
from yak.rest_social_network.models import Tag, Comment, Follow, Flag, Share, Like
from yak.rest_user.serializers import UserSerializer

                return self.context['request'].user.following.get(content_type=content_type, object_id=obj.pk).pk
            except Follow.DoesNotExist:
                pass
        return None


class TagSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tag
        fields = ('name', 'id')


class CommentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Comment
        exclude = ('related_tags',)

    def __init__(self, *args, **kwargs):
        """
        The `user` field is added here to help with recursive import issues mentioned in rest_user.serializers
        """
        super(CommentSerializer, self).__init__(*args, **kwargs)
        self.fields["user"] = UserSerializer(read_only=True, default=serializers.CurrentUserDefault())


class FollowSerializer(serializers.ModelSerializer):
    follower = UserSerializer(read_only=True, source="user")
    following = serializers.SerializerMethodField('get_user_follow')

    class Meta:

        model = Follow