Skip to content

Commit

Permalink
ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegerrits committed Feb 3, 2025
1 parent 2c78a8f commit 153c671
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions vespadb/observations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ def save(self, *args: Any, **kwargs: Any) -> None:
logger.info(f"Save method for observation {self.id if self.id else 'new'}: Setting municipality={self.municipality}, province={self.province}, anb={self.anb}")

super().save(*args, **kwargs)

class Meta:
ordering = ['id']

class Export(models.Model):
"""Model for tracking observation exports."""
Expand Down
4 changes: 3 additions & 1 deletion vespadb/observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def get_queryset(self) -> QuerySet:
Unauthenticated users see only unreserved observations.
"""
base_queryset = super().get_queryset()
if not self.request.query_params.get("ordering"):
base_queryset = base_queryset.order_by("id")
order_params = self.request.query_params.get("ordering", "")

if "municipality_name" in order_params:
Expand Down Expand Up @@ -404,7 +406,7 @@ def geojson(self, request: Request) -> HttpResponse:
if bbox:
queryset = queryset.filter(location__within=bbox)

queryset = queryset.annotate(point=Transform("location", 4326))
queryset = queryset.order_by("id").annotate(point=Transform("location", 4326))

features = [
{
Expand Down

0 comments on commit 153c671

Please sign in to comment.