[extensions-web/wip/api/v1: 17/19] extensions: api: added recommended field




commit 45c9a737213dfc4e0467da0c55bde09301a55de2
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Sun Nov 22 12:39:12 2020 +0400

    extensions: api: added recommended field

 sweettooth/extensions/documents.py                     |  1 +
 .../migrations/0009_extension_recommended.py           | 18 ++++++++++++++++++
 sweettooth/extensions/models.py                        |  1 +
 sweettooth/extensions/views.py                         |  4 ++++
 4 files changed, 24 insertions(+)
---
diff --git a/sweettooth/extensions/documents.py b/sweettooth/extensions/documents.py
index b1f7db2d..9d1b171c 100644
--- a/sweettooth/extensions/documents.py
+++ b/sweettooth/extensions/documents.py
@@ -36,6 +36,7 @@ class ExtensionDocument(Document):
             'updated',
             'downloads',
             'popularity',
+            'recommended',
         ]
 
     def get_queryset(self):
diff --git a/sweettooth/extensions/migrations/0009_extension_recommended.py 
b/sweettooth/extensions/migrations/0009_extension_recommended.py
new file mode 100644
index 00000000..a8bcb7d2
--- /dev/null
+++ b/sweettooth/extensions/migrations/0009_extension_recommended.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.12 on 2020-05-26 21:26
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('extensions', '0008_auto_20200523_1243'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='extension',
+            name='recommended',
+            field=models.BooleanField(default=False),
+        ),
+    ]
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 7dce75a1..22dc7c12 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -114,6 +114,7 @@ class Extension(models.Model):
     updated = models.DateTimeField(default=None, null=True)
     downloads = models.PositiveIntegerField(default=0)
     popularity = models.IntegerField(default=0)
+    recommended = models.BooleanField(default=False)
 
     class Meta:
         permissions = (
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index be87609d..81583715 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -62,6 +62,7 @@ class ExtensionsViewSet(mixins.ListModelMixin,
     serializer_class = serializers.ExtensionSerializer
     pagination_class = ExtensionsPagination
     filter_backends = [DjangoFilterBackend, filters.OrderingFilter]
+    filterset_fields = ['recommended']
     ordering_fields = ['created', 'updated', 'downloads', 'popularity', '?']
     page_size = 25
     page_size_query_param = 'page_size'
@@ -159,6 +160,9 @@ class ExtensionsViewSet(mixins.ListModelMixin,
             fields=ExtensionDocument.document_fields()
         )
 
+        if self.request.query_params.get('recommended') in ("true", "1"):
+            queryset = queryset.filter("term", recommended=True)
+
         ordering = self.request.query_params.get('ordering')
         ordering_field = (
             ordering


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]