Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django.db.models.import Count
- class Tag(models.Model):
- name = models.CharField(max_length=255, default='')
- def __unicode__(self):
- return self.name
- class Article(models.Model):
- title = models.CharField(max_length=255, default='')
- body = models.TextField(default='')
- tag = models.ManyToManyField(Tag)
- def __unicode__(self):
- return self.title
- a = Article.objects.get(pk=3)
- a.tag.through.objects.all().values('tag_id').annotate(article_count=Count('article')).order_by('-article_count')[0]
Advertisement
Add Comment
Please, Sign In to add comment