mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 13:31:08 -05:00
feat: Add continent and park type fields to Park and ParkLocation models; update API filters and documentation
This commit is contained in:
@@ -240,10 +240,15 @@ class ParkListCreateAPIView(APIView):
|
||||
if city:
|
||||
qs = qs.filter(location__city__iexact=city)
|
||||
|
||||
# NOTE: continent and park_type filters are not implemented because
|
||||
# these fields don't exist in the current Django models:
|
||||
# - ParkLocation model has no 'continent' field
|
||||
# - Park model has no 'park_type' field
|
||||
# Continent filter (now available field)
|
||||
continent = params.get("continent")
|
||||
if continent:
|
||||
qs = qs.filter(location__continent__iexact=continent)
|
||||
|
||||
# Park type filter (now available field)
|
||||
park_type = params.get("park_type")
|
||||
if park_type:
|
||||
qs = qs.filter(park_type=park_type)
|
||||
|
||||
# Status filter (available field)
|
||||
status_filter = params.get("status")
|
||||
@@ -559,16 +564,24 @@ class FilterOptionsAPIView(APIView):
|
||||
|
||||
# Try to get dynamic options from database
|
||||
try:
|
||||
# NOTE: continent field doesn't exist in ParkLocation model, so we use static list
|
||||
continents = [
|
||||
"North America",
|
||||
"South America",
|
||||
"Europe",
|
||||
"Asia",
|
||||
"Africa",
|
||||
"Australia",
|
||||
"Antarctica"
|
||||
]
|
||||
# Get continents from database (now available field)
|
||||
continents = list(Park.objects.exclude(
|
||||
location__continent__isnull=True
|
||||
).exclude(
|
||||
location__continent__exact=''
|
||||
).values_list('location__continent', flat=True).distinct().order_by('location__continent'))
|
||||
|
||||
# Fallback to static list if no continents in database
|
||||
if not continents:
|
||||
continents = [
|
||||
"North America",
|
||||
"South America",
|
||||
"Europe",
|
||||
"Asia",
|
||||
"Africa",
|
||||
"Australia",
|
||||
"Antarctica"
|
||||
]
|
||||
|
||||
countries = list(Park.objects.exclude(
|
||||
location__country__isnull=True
|
||||
@@ -582,22 +595,11 @@ class FilterOptionsAPIView(APIView):
|
||||
location__state__exact=''
|
||||
).values_list('location__state', flat=True).distinct().order_by('location__state'))
|
||||
|
||||
# Try to use ModelChoices if available
|
||||
if HAVE_MODELCHOICES and ModelChoices is not None:
|
||||
try:
|
||||
park_types = ModelChoices.get_park_type_choices()
|
||||
except Exception:
|
||||
park_types = [
|
||||
{"value": "THEME_PARK", "label": "Theme Park"},
|
||||
{"value": "AMUSEMENT_PARK", "label": "Amusement Park"},
|
||||
{"value": "WATER_PARK", "label": "Water Park"},
|
||||
]
|
||||
else:
|
||||
park_types = [
|
||||
{"value": "THEME_PARK", "label": "Theme Park"},
|
||||
{"value": "AMUSEMENT_PARK", "label": "Amusement Park"},
|
||||
{"value": "WATER_PARK", "label": "Water Park"},
|
||||
]
|
||||
# Get park types from model choices (now available field)
|
||||
park_types = [
|
||||
{"value": choice[0], "label": choice[1]}
|
||||
for choice in Park.PARK_TYPE_CHOICES
|
||||
]
|
||||
|
||||
return Response({
|
||||
"park_types": park_types,
|
||||
|
||||
Reference in New Issue
Block a user