Skip to content

Commit 791723b

Browse files
authored
Fix popular_tags query (#23)
1 parent 1969863 commit 791723b

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

backend/articles/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
from django.db import models
2+
from django.db.models import Count
23
from django.db.models.signals import pre_save
34
from django.dispatch import receiver
45
from django.utils.text import slugify
56

67

78
class TagManager(models.Manager):
89
def popular_tags(self):
9-
return (
10+
return list(
1011
self.get_queryset()
11-
.annotate(count=models.Count("articles"))
12+
.values("name")
13+
.annotate(count=Count("articles"))
1214
.order_by("-count")[:10]
15+
.values_list("name", flat=True)
1316
)
1417

1518

backend/articles/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ def favorite(self, request, *args, **kwargs):
6666
class TagListView(APIView):
6767
@staticmethod
6868
def get(request):
69-
popular_tags = Tag.objects.popular_tags()
70-
return Response(
71-
{"tags": list(popular_tags.values_list("name", flat=True))}
72-
)
69+
return Response({"tags": Tag.objects.popular_tags()})
7370

7471

7572
class CommentViewSet(

frontend/src/app/shared/error-message/error-message.component.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
<ng-container *ngIf="errors">
99
<ng-container *ngFor="let error of errors | keyvalue">
10-
<ng-container *ngIf="error.key">
10+
<ng-container *ngIf="error.key && error.key != 'non_field_errors'; else noKeyError">
1111
<li>{{error.key | titlecase}}: {{error.value}}</li>
1212
</ng-container>
13-
14-
<ng-container *ngIf="!error.key">
13+
<ng-template #noKeyError>
1514
<li>{{error.value}}</li>
16-
</ng-container>
15+
</ng-template>
1716
</ng-container>
1817
</ng-container>
1918

0 commit comments

Comments
 (0)