[extensions-web/wip/api/v1: 28/33] extensions: api: added recommended field




commit 52e29d8650c0d93cad034c649a8e183e24c115de
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/0013_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 b1f7db2..9d1b171 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/0013_extension_recommended.py 
b/sweettooth/extensions/migrations/0013_extension_recommended.py
new file mode 100644
index 0000000..5c70c6b
--- /dev/null
+++ b/sweettooth/extensions/migrations/0013_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', '0012_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 b420edd..bcd0ee7 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -130,6 +130,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 c151b1a..24c1211 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -63,6 +63,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'
@@ -160,6 +161,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]