List user's tags on PrivateUserResource.

master
Nick Sergeant 2015-08-28 12:08:27 -04:00
parent daab416647
commit 3bafbb7402
1 changed files with 15 additions and 1 deletions

View File

@ -326,9 +326,23 @@ class PrivateUserResource(ModelResource):
'total_views': Snipt.objects.filter(user=bundle.obj.id).aggregate(
models.Sum('views'))['views__sum']
}
user_snipts = Snipt.objects.filter(user=bundle.obj)
user_tags = [
snipt['tags'] for snipt in user_snipts.values('tags').distinct()
]
tags = [
tag['name'] for tag in
Tag.objects.filter(id__in=user_tags).values('name').distinct()
]
bundle.data['tags'] = tags
bundle.data['lexers'] = [
snipt['lexer'] for snipt in Snipt.objects.filter(user=bundle.obj)
snipt['lexer'] for snipt in user_snipts
.values('lexer').distinct()]
return bundle