Awesome counts
parent
b1c65bc6e4
commit
9dc8d350ac
|
@ -22,7 +22,7 @@ class PublicCommentSniptResource(ModelResource):
|
||||||
|
|
||||||
class PublicTagResource(ModelResource):
|
class PublicTagResource(ModelResource):
|
||||||
class Meta:
|
class Meta:
|
||||||
tags = Tag.objects.all()
|
tags = Tag.objects.filter(snipt__public=True)
|
||||||
annotated = tags.annotate(count=Count('taggit_taggeditem_items__id'))
|
annotated = tags.annotate(count=Count('taggit_taggeditem_items__id'))
|
||||||
queryset = annotated.order_by('-count')
|
queryset = annotated.order_by('-count')
|
||||||
resource_name = 'tag'
|
resource_name = 'tag'
|
||||||
|
@ -31,6 +31,7 @@ class PublicTagResource(ModelResource):
|
||||||
def dehydrate(self, bundle):
|
def dehydrate(self, bundle):
|
||||||
bundle.data['absolute_url'] = '/public/tag/%s/' % bundle.obj.slug
|
bundle.data['absolute_url'] = '/public/tag/%s/' % bundle.obj.slug
|
||||||
bundle.data['snipts'] = '/api/public/snipt/?tag=%d' % bundle.obj.id
|
bundle.data['snipts'] = '/api/public/snipt/?tag=%d' % bundle.obj.id
|
||||||
|
bundle.data['count'] = bundle.obj.taggit_taggeditem_items.filter(snipt__public=True).count()
|
||||||
return bundle
|
return bundle
|
||||||
|
|
||||||
class PublicCommentResource(ModelResource):
|
class PublicCommentResource(ModelResource):
|
||||||
|
@ -68,6 +69,7 @@ class PublicSniptResource(ModelResource):
|
||||||
for tag in bundle.obj.tags.all():
|
for tag in bundle.obj.tags.all():
|
||||||
bundle.data['tags'].append({
|
bundle.data['tags'].append({
|
||||||
'name': tag.name,
|
'name': tag.name,
|
||||||
|
'count': tag.taggit_taggeditem_items.filter(snipt__public=True).count(),
|
||||||
'absolute_url': '/public/tag/%s/' % tag.slug,
|
'absolute_url': '/public/tag/%s/' % tag.slug,
|
||||||
'resource_uri': '/api/public/tag/%d/' % tag.id,
|
'resource_uri': '/api/public/tag/%d/' % tag.id,
|
||||||
'snipts': '/api/public/snipt/?tag=%d' % tag.id,
|
'snipts': '/api/public/snipt/?tag=%d' % tag.id,
|
||||||
|
|
Loading…
Reference in New Issue