# Path: shiori/bookmark/models.py
# class Category(BaseObject):
#     """ Category model """
#     category = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'category'
# 
#     def __unicode__(self):
#         return self.category
# 
# class Tag(BaseObject):
#     """ Tag model """
#     tag = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'tag'
# 
#     def __unicode__(self):
#         return self.tag
# 
# class Bookmark(BaseObject):
#     """ Bookmark model """
#     url = models.URLField()
#     title = models.CharField(max_length=255)
#     category = models.ForeignKey(Category)
#     tags = models.ManyToManyField(Tag, through='BookmarkTag')
#     registered_datetime = models.DateTimeField(auto_now=True,
#                                                auto_now_add=True)
#     description = models.TextField(blank=True)
#     owner = models.ForeignKey(User)
#     is_hide = models.BooleanField(default=False)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'bookmark'
#         unique_together = ('url', 'owner')
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         """ bookmark permalink path """
#         return "/shiori/b/%s" % self.id
# 
# class BookmarkTag(models.Model):
#     """ BookmarkTag model """
#     id = models.AutoField(primary_key=True)
#     bookmark = models.ForeignKey(Bookmark,
#                                  db_column='bookmark_id',
#                                  to_field='id')
#     tag = models.ForeignKey(Tag,
#                             db_column='tag_id',
#                             to_field='id')
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'bookmark_tag'
#         unique_together = ('bookmark', 'tag')
# 
# class FeedSubscription(BaseObject):
#     """ FeedSubsscription model """
#     url = models.URLField()
#     name = models.CharField(max_length=255, editable=False)
#     owner = models.ForeignKey(User)
#     default_category = models.ForeignKey(Category)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'feed_subscription'
#         unique_together = ('url', 'owner')
# 
#     def __unicode__(self):
#         return self.url


from rest_framework import serializers
from shiori.bookmark.models import (Category,
                                    Tag,
                                    Bookmark,
                                    BookmarkTag,
                                    FeedSubscription)

class CategorySerializer(serializers.ModelSerializer):
    """ Serializer for shiori.bookmark.models.Category """

    class Meta(object):
        """ Meta class of CategorySerializer """
        model = Category
        fields = ('id', 'category')


class TagSerializer(serializers.ModelSerializer):
    """ Serializer for shiori.bookmark.models.Tag """

    class Meta(object):
        """ Meta class of TagSerializer """
        model = Tag
        fields = ('id', 'tag')


class BookmarkSerializer(serializers.ModelSerializer):
    """ Serializer for shiori.bookmark.models.Bookmark """
    title = serializers.Field(source='title')
    category = serializers.SlugRelatedField(many=False, slug_field='category')
    category_id = serializers.Field(source='category.id')
    tags = serializers.SlugRelatedField(many=True, slug_field='tag',
                                        read_only=True)
    owner = serializers.Field(source='owner.username')

    class Meta(object):
        """ Meta class of BookmarkSerializer """

# Path: shiori/bookmark/models.py
# class Category(BaseObject):
#     """ Category model """
#     category = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'category'
# 
#     def __unicode__(self):
#         return self.category
# 
# class Tag(BaseObject):
#     """ Tag model """
#     tag = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'tag'
# 
#     def __unicode__(self):
#         return self.tag
# 
# class Bookmark(BaseObject):
#     """ Bookmark model """
#     url = models.URLField()
#     title = models.CharField(max_length=255)
#     category = models.ForeignKey(Category)
#     tags = models.ManyToManyField(Tag, through='BookmarkTag')
#     registered_datetime = models.DateTimeField(auto_now=True,
#                                                auto_now_add=True)
#     description = models.TextField(blank=True)
#     owner = models.ForeignKey(User)
#     is_hide = models.BooleanField(default=False)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'bookmark'
#         unique_together = ('url', 'owner')
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         """ bookmark permalink path """
#         return "/shiori/b/%s" % self.id
# 
# class BookmarkTag(models.Model):
#     """ BookmarkTag model """
#     id = models.AutoField(primary_key=True)
#     bookmark = models.ForeignKey(Bookmark,
#                                  db_column='bookmark_id',
#                                  to_field='id')
#     tag = models.ForeignKey(Tag,
#                             db_column='tag_id',
#                             to_field='id')
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'bookmark_tag'
#         unique_together = ('bookmark', 'tag')
# 
# class FeedSubscription(BaseObject):
#     """ FeedSubsscription model """
#     url = models.URLField()
#     name = models.CharField(max_length=255, editable=False)
#     owner = models.ForeignKey(User)
#     default_category = models.ForeignKey(Category)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'feed_subscription'
#         unique_together = ('url', 'owner')
# 
#     def __unicode__(self):
#         return self.url


# Path: shiori/api/serializers.py
from rest_framework import serializers
from shiori.bookmark.models import (Category,
                                    Tag,
                                    Bookmark,
                                    BookmarkTag,
                                    FeedSubscription)


class CategorySerializer(serializers.ModelSerializer):
    """ Serializer for shiori.bookmark.models.Category """

    class Meta(object):
        """ Meta class of CategorySerializer """
        model = Category
        fields = ('id', 'category')


class TagSerializer(serializers.ModelSerializer):
    """ Serializer for shiori.bookmark.models.Tag """

    class Meta(object):
        """ Meta class of TagSerializer """
        model = Tag
        fields = ('id', 'tag')


class BookmarkSerializer(serializers.ModelSerializer):
    """ Serializer for shiori.bookmark.models.Bookmark """
    title = serializers.Field(source='title')
    category = serializers.SlugRelatedField(many=False, slug_field='category')
    category_id = serializers.Field(source='category.id')
    tags = serializers.SlugRelatedField(many=True, slug_field='tag',
                                        read_only=True)
    owner = serializers.Field(source='owner.username')

    class Meta(object):
        """ Meta class of BookmarkSerializer """

        model = Bookmark