# Path: django_fortunes/managers.py
# class FortuneManager(models.Manager):
#     def latest(self):
#         "Generates a query to retrieve latest fortunes"
#         return self.published().order_by('-pub_date')
# 
#     def latest_by_author(self, author):
#         "Generates a query to retrieve latest fortunes by a given author"
#         return self.published().filter(author__username=author).order_by('-pub_date')
# 
#     def published(self):
#         "Generates a query to retrieve published fortunes"
#         return self.get_query_set().filter(pub_date__lte=datetime.datetime.now())
#     
#     def top_authors(self):
#         "Generates a query to retrieve top fortune authors"
#         return self.published().values('author__username')\
#                                .annotate(nb=models.Count('id'))\
#                                .order_by('-nb')


from datetime import datetime
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.comments.models import Comment
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
from django_fortunes.managers import FortuneManager



class Fortune(models.Model):
    author = models.ForeignKey(User)
    title = models.CharField(max_length=200, blank=False)
    slug = models.SlugField(_('slug'), db_index=True, max_length=255, unique_for_date='pub_date')

# Path: django_fortunes/managers.py
# class FortuneManager(models.Manager):
#     def latest(self):
#         "Generates a query to retrieve latest fortunes"
#         return self.published().order_by('-pub_date')
# 
#     def latest_by_author(self, author):
#         "Generates a query to retrieve latest fortunes by a given author"
#         return self.published().filter(author__username=author).order_by('-pub_date')
# 
#     def published(self):
#         "Generates a query to retrieve published fortunes"
#         return self.get_query_set().filter(pub_date__lte=datetime.datetime.now())
#     
#     def top_authors(self):
#         "Generates a query to retrieve top fortune authors"
#         return self.published().values('author__username')\
#                                .annotate(nb=models.Count('id'))\
#                                .order_by('-nb')


# Path: django_fortunes/models.py
from datetime import datetime
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.comments.models import Comment
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
from django_fortunes.managers import FortuneManager




class Fortune(models.Model):
    author = models.ForeignKey(User)
    title = models.CharField(max_length=200, blank=False)
    slug = models.SlugField(_('slug'), db_index=True, max_length=255, unique_for_date='pub_date')

    content = models.TextField(blank=False)