Skip to content

Commit

Permalink
[SMP-220] Trier areas et polygones par ordre alphabétique (#52)
Browse files Browse the repository at this point in the history
* added alphabetical order for Polygon and Areas ViewSet

* added indexes to the 'label' field of Area and Polygons Models
  • Loading branch information
JohnnyChen765 authored Mar 1, 2019
1 parent 29b4ea2 commit 402dd98
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 8 additions & 0 deletions mds/apis/prv_api/service_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from mds.access_control.scopes import SCOPE_PRV_API
from mds.apis import utils

from rest_framework import filters


class PolygonRequestSerializer(serializers.ModelSerializer):
"""What we expect for a geographic polygon.
Expand Down Expand Up @@ -73,6 +75,9 @@ class Meta:
class PolygonViewSet(utils.MultiSerializerViewSetMixin, viewsets.ModelViewSet):
permission_classes = (require_scopes(SCOPE_PRV_API),)
queryset = models.Polygon.objects.prefetch_related("areas").all()
filter_backends = (filters.OrderingFilter,)
ordering_fields = ("label",)
ordering = "label"
lookup_field = "id"
serializer_class = PolygonResponseSerializer
serializers_mapping = {
Expand Down Expand Up @@ -188,6 +193,9 @@ class Meta:
class AreaViewSet(utils.MultiSerializerViewSetMixin, viewsets.ModelViewSet):
permission_classes = (require_scopes(SCOPE_PRV_API),)
queryset = models.Area.objects.prefetch_related("polygons").all()
filter_backends = (filters.OrderingFilter,)
ordering_fields = ("label",)
ordering = "label"
lookup_field = "id"
serializer_class = AreaResponseSerializer
serializers_mapping = {
Expand Down
24 changes: 24 additions & 0 deletions mds/migrations/0011_added_index_to_polygon_and_area_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.1.7 on 2019-03-01 11:13

from django.db import migrations
import mds.models


class Migration(migrations.Migration):

dependencies = [
('mds', '0010_device_dn_battery_pct'),
]

operations = [
migrations.AlterField(
model_name='area',
name='label',
field=mds.models.UnboundedCharField(blank=True, db_index=True, null=True),
),
migrations.AlterField(
model_name='polygon',
name='label',
field=mds.models.UnboundedCharField(blank=True, db_index=True, null=True),
),
]
4 changes: 2 additions & 2 deletions mds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Polygon(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
creation_date = models.DateTimeField(default=utils.timezone.now)
deletion_date = models.DateTimeField(null=True, blank=True)
label = UnboundedCharField(null=True, blank=True)
label = UnboundedCharField(null=True, blank=True, db_index=True)
geom = gis_models.PolygonField()
properties = pg_fields.JSONField(default=dict, encoder=encoders.JSONEncoder)

Expand All @@ -198,7 +198,7 @@ class Area(models.Model):
default=datetime.datetime(2012, 1, 1, tzinfo=datetime.timezone.utc)
)
deletion_date = models.DateTimeField(null=True, blank=True)
label = UnboundedCharField(null=True, blank=True)
label = UnboundedCharField(null=True, blank=True, db_index=True)
polygons = models.ManyToManyField(Polygon, blank=True, related_name="areas")
providers = models.ManyToManyField(Provider, blank=True, related_name="areas")
color = models.CharField(
Expand Down

0 comments on commit 402dd98

Please sign in to comment.