Created
April 22, 2010 20:23
-
-
Save n1k0/375770 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.db.models import Avg, Max, Min, Count | |
class Fortune(models.Model): | |
author = models.CharField(max_length=45, blank=False) | |
title = models.CharField(max_length=200, blank=False) | |
content = models.TextField(blank=False) | |
pub_date = models.DateTimeField('date published', auto_now_add=True) | |
votes = models.IntegerField(default=0) | |
def __unicode__(self): | |
return "%s, from %s" % (self.title, self.author) | |
@staticmethod | |
def top_authors(max): | |
return Fortune.objects.values('author').annotate(nb=Count('id')).order_by('-nb')[:max] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Retrieves top fortune authors | |
SELECT author, count(id) AS nb FROM fortunes GROUP BY author ORDER BY nb DESC; |
Ah, nice to know! I'll check out managers asap. Thanks for the kind feedback :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(you have used symfony for too long ;-)