mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 07:19:36 +02:00
chore: Add created_at field to Adventure and Collection models
This commit is contained in:
parent
040d5a755f
commit
704eb6f6de
6 changed files with 87 additions and 4 deletions
|
@ -31,11 +31,11 @@ class AdventureViewSet(viewsets.ModelViewSet):
|
|||
pagination_class = StandardResultsSetPagination
|
||||
|
||||
def apply_sorting(self, queryset):
|
||||
order_by = self.request.query_params.get('order_by', 'name')
|
||||
order_by = self.request.query_params.get('order_by', 'created_at')
|
||||
order_direction = self.request.query_params.get('order_direction', 'asc')
|
||||
include_collections = self.request.query_params.get('include_collections', 'true')
|
||||
|
||||
valid_order_by = ['name', 'type', 'date', 'rating']
|
||||
valid_order_by = ['name', 'type', 'date', 'rating', 'created_at']
|
||||
if order_by not in valid_order_by:
|
||||
order_by = 'name'
|
||||
|
||||
|
@ -52,6 +52,13 @@ class AdventureViewSet(viewsets.ModelViewSet):
|
|||
if order_direction == 'desc':
|
||||
ordering = f'-{ordering}'
|
||||
|
||||
# reverse ordering for created_at field
|
||||
if order_by == 'created_at':
|
||||
if order_direction == 'asc':
|
||||
ordering = '-created_at'
|
||||
else:
|
||||
ordering = 'created_at'
|
||||
|
||||
print(f"Ordering by: {ordering}") # For debugging
|
||||
|
||||
if include_collections == 'false':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue