# Path: feedme/utils.py
# def unique_slugify(instance, value, slug_field_name='slug', queryset=None,
#                    slug_separator='-'):
#     """
# Calculates and stores a unique slug of ``value`` for an instance.
# 
# ``slug_field_name`` should be a string matching the name of the field to
# store the slug in (and the field to check against for uniqueness).
# 
# ``queryset`` usually doesn't need to be explicitly provided - it'll default
# to using the ``.all()`` queryset from the model's default manager.
# """
#     slug_field = instance._meta.get_field(slug_field_name)
# 
#     slug = getattr(instance, slug_field.attname)
#     slug_len = slug_field.max_length
# 
#     # Sort out the initial slug, limiting its length if necessary.
#     slug = slugify(value)
#     if slug_len:
#         slug = slug[:slug_len]
#     slug = _slug_strip(slug, slug_separator)
#     original_slug = slug
# 
#     # Create the queryset if one wasn't explicitly provided and exclude the
#     # current instance from the queryset.
#     if queryset is None:
#         queryset = instance.__class__._default_manager.all()
#     if instance.pk:
#         queryset = queryset.exclude(pk=instance.pk)
# 
#     # Find a unique slug. If one matches, at '-2' to the end and try again
#     # (then '-3', etc).
#     next = 2
#     while not slug or queryset.filter(**{slug_field_name: slug}):
#         slug = original_slug
#         end = '%s%s' % (slug_separator, next)
#         if slug_len and len(slug) + len(end) > slug_len:
#             slug = slug[:slug_len-len(end)]
#             slug = _slug_strip(slug, slug_separator)
#         slug = '%s%s' % (slug, end)
#         next += 1
# 
#     setattr(instance, slug_field.attname, slug)
# 
# Path: feedme/managers.py
# class FeedItemManager(Manager):
#     def get_queryset(self):
#         return FeedItemQuerySet(self.model, using=self._db)
# 
#     def category(self, category_slug):
#         return self.get_queryset().category(category_slug)
# 
#     def my_feed_items(self, user):
#         return self.get_queryset().my_feed_items(user)
# 
#     def un_read(self):
#         return self.get_queryset().un_read()
# 
#     def read(self):
#         return self.get_queryset().read()
# 
#     def yesterday(self):
#         return self.get_queryset().yesterday()


import datetime
import feedparser
from time import mktime
from django.utils.encoding import python_2_unicode_compatible
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django.utils import timezone
from feedme.utils import unique_slugify
from .managers import FeedItemManager
            from .tasks import update_feed
Author: Derek Stegelman
"""
from __future__ import unicode_literals








@python_2_unicode_compatible
class Category(models.Model):
    """
    Category model
    """
    name = models.CharField(max_length=250, blank=True)
    slug = models.SlugField(blank=True, null=True, editable=False)
    user = models.ForeignKey(User, blank=True, null=True)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        """
        Updated Save to slug the name.
        :param args:
        :param kwargs:
        :return:
        """

# Path: feedme/utils.py
# def unique_slugify(instance, value, slug_field_name='slug', queryset=None,
#                    slug_separator='-'):
#     """
# Calculates and stores a unique slug of ``value`` for an instance.
# 
# ``slug_field_name`` should be a string matching the name of the field to
# store the slug in (and the field to check against for uniqueness).
# 
# ``queryset`` usually doesn't need to be explicitly provided - it'll default
# to using the ``.all()`` queryset from the model's default manager.
# """
#     slug_field = instance._meta.get_field(slug_field_name)
# 
#     slug = getattr(instance, slug_field.attname)
#     slug_len = slug_field.max_length
# 
#     # Sort out the initial slug, limiting its length if necessary.
#     slug = slugify(value)
#     if slug_len:
#         slug = slug[:slug_len]
#     slug = _slug_strip(slug, slug_separator)
#     original_slug = slug
# 
#     # Create the queryset if one wasn't explicitly provided and exclude the
#     # current instance from the queryset.
#     if queryset is None:
#         queryset = instance.__class__._default_manager.all()
#     if instance.pk:
#         queryset = queryset.exclude(pk=instance.pk)
# 
#     # Find a unique slug. If one matches, at '-2' to the end and try again
#     # (then '-3', etc).
#     next = 2
#     while not slug or queryset.filter(**{slug_field_name: slug}):
#         slug = original_slug
#         end = '%s%s' % (slug_separator, next)
#         if slug_len and len(slug) + len(end) > slug_len:
#             slug = slug[:slug_len-len(end)]
#             slug = _slug_strip(slug, slug_separator)
#         slug = '%s%s' % (slug, end)
#         next += 1
# 
#     setattr(instance, slug_field.attname, slug)
# 
# Path: feedme/managers.py
# class FeedItemManager(Manager):
#     def get_queryset(self):
#         return FeedItemQuerySet(self.model, using=self._db)
# 
#     def category(self, category_slug):
#         return self.get_queryset().category(category_slug)
# 
#     def my_feed_items(self, user):
#         return self.get_queryset().my_feed_items(user)
# 
#     def un_read(self):
#         return self.get_queryset().un_read()
# 
#     def read(self):
#         return self.get_queryset().read()
# 
#     def yesterday(self):
#         return self.get_queryset().yesterday()


# Path: feedme/models.py
import datetime
import feedparser
from time import mktime
from django.utils.encoding import python_2_unicode_compatible
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django.utils import timezone
from feedme.utils import unique_slugify
from .managers import FeedItemManager
            from .tasks import update_feed

Author: Derek Stegelman
"""
from __future__ import unicode_literals








@python_2_unicode_compatible
class Category(models.Model):
    """
    Category model
    """
    name = models.CharField(max_length=250, blank=True)
    slug = models.SlugField(blank=True, null=True, editable=False)
    user = models.ForeignKey(User, blank=True, null=True)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        """
        Updated Save to slug the name.
        :param args:
        :param kwargs:
        :return:
        """

        unique_slugify(self, self.name)