# Path: jellyblog/models.py
# class Document(models.Model):
#     # 문서 Model
#     def __str__(self):
#         return self.title
# 
#     id = models.AutoField(primary_key=True)
#     category = models.ForeignKey(Category)
#     title = models.CharField(max_length=100)
#     content = models.TextField()
#     time = models.DateTimeField(auto_now_add=True)
#     meta_tag = models.CharField(max_length=150)
#     view_count = models.IntegerField(default=0, editable=False)
#     public_doc = models.BooleanField()
#     thumbnail = models.ImageField(null=True, upload_to="thumnail_img/")
#     update_time = models.DateTimeField(auto_now=True)
#     is_markdown = models.BooleanField()
#     linebreaks = models.BooleanField()
# 
#     def read(self):
#         self.view_count += 1
#         self.save()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'detail', (), {'document_id': self.id}
# 
#     @classmethod
#     def search_document(cls, query):
#         if len(query) == 0:
#             return None
#         return cls.objects.filter((
#             Q(title__icontains=query) | Q(content__icontains=query))
#             & Q(public_doc=True))


from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from .models import Document


class LatestFeed(Feed):
    title = "젤리의 망상 최근 Feeds"
    link = "/blognews/"
    description = "젤리의 망상의 피드입니다."

    def items(self):
        return Document.objects.filter(public_doc=True).order_by('-time')[:5]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.content

    def item_link(self, item):
        return reverse('detail', args=[item.pk])


class AllPublickFeed(Feed):
    title = "젤리의 망상 Feeds"
    link = "/blognews/"
    description = "젤리의 망상 Feeds"

    def items(self):

# Path: jellyblog/models.py
# class Document(models.Model):
#     # 문서 Model
#     def __str__(self):
#         return self.title
# 
#     id = models.AutoField(primary_key=True)
#     category = models.ForeignKey(Category)
#     title = models.CharField(max_length=100)
#     content = models.TextField()
#     time = models.DateTimeField(auto_now_add=True)
#     meta_tag = models.CharField(max_length=150)
#     view_count = models.IntegerField(default=0, editable=False)
#     public_doc = models.BooleanField()
#     thumbnail = models.ImageField(null=True, upload_to="thumnail_img/")
#     update_time = models.DateTimeField(auto_now=True)
#     is_markdown = models.BooleanField()
#     linebreaks = models.BooleanField()
# 
#     def read(self):
#         self.view_count += 1
#         self.save()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'detail', (), {'document_id': self.id}
# 
#     @classmethod
#     def search_document(cls, query):
#         if len(query) == 0:
#             return None
#         return cls.objects.filter((
#             Q(title__icontains=query) | Q(content__icontains=query))
#             & Q(public_doc=True))


# Path: jellyblog/feeds.py
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from .models import Document



class LatestFeed(Feed):
    title = "젤리의 망상 최근 Feeds"
    link = "/blognews/"
    description = "젤리의 망상의 피드입니다."

    def items(self):
        return Document.objects.filter(public_doc=True).order_by('-time')[:5]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.content

    def item_link(self, item):
        return reverse('detail', args=[item.pk])


class AllPublickFeed(Feed):
    title = "젤리의 망상 Feeds"
    link = "/blognews/"
    description = "젤리의 망상 Feeds"

    def items(self):

        return Document.objects.filter(public_doc=True).order_by('-time')