diff --git a/parks/__pycache__/models.cpython-312.pyc b/parks/__pycache__/models.cpython-312.pyc index 98aaed34..a2e154aa 100644 Binary files a/parks/__pycache__/models.cpython-312.pyc and b/parks/__pycache__/models.cpython-312.pyc differ diff --git a/parks/__pycache__/urls.cpython-312.pyc b/parks/__pycache__/urls.cpython-312.pyc index b2afbce0..016ae9e8 100644 Binary files a/parks/__pycache__/urls.cpython-312.pyc and b/parks/__pycache__/urls.cpython-312.pyc differ diff --git a/parks/__pycache__/views.cpython-312.pyc b/parks/__pycache__/views.cpython-312.pyc index 330dd848..af4d4b64 100644 Binary files a/parks/__pycache__/views.cpython-312.pyc and b/parks/__pycache__/views.cpython-312.pyc differ diff --git a/parks/models.py b/parks/models.py index 75915989..7f767ddd 100644 --- a/parks/models.py +++ b/parks/models.py @@ -66,17 +66,7 @@ class Park(models.Model): self.slug = slugify(self.name) # Update the location field to combine country, region, and city - location_parts = [] - if self.city: - location_parts.append(self.city.name) - if self.region: - location_parts.append(self.region.name) - if self.country: - location_parts.append(self.country.name) - - # Only update location if we have parts to combine - if location_parts: - self.location = ', '.join(location_parts) + self.location = self.get_formatted_location() super().save(*args, **kwargs) @@ -93,15 +83,15 @@ class Park(models.Model): raise cls.DoesNotExist("No park found with this slug") def get_formatted_location(self): - """Get a formatted location string combining city, region, and country""" - location_parts = [] - if self.city: - location_parts.append(self.city.name) - if self.region: - location_parts.append(self.region.name) - if self.country: - location_parts.append(self.country.name) - return ', '.join(location_parts) + """Get a formatted location string: $COUNTRY, $REGION, $CITY""" + location = self.country.name + + if self.region and self.city: + location += f", {self.region.name}, {self.city.name}" + elif self.region: + location += f", {self.region.name}" + + return location class ParkArea(models.Model): name = models.CharField(max_length=255) diff --git a/parks/urls.py b/parks/urls.py index 748c128f..d2db9d9f 100644 --- a/parks/urls.py +++ b/parks/urls.py @@ -11,7 +11,6 @@ urlpatterns = [ path('ajax/countries/', views.get_countries, name='get_countries'), path('ajax/regions/', views.get_regions, name='get_regions'), path('ajax/cities/', views.get_cities, name='get_cities'), - path('ajax/locations/', views.get_locations, name='get_locations'), path('/', views.ParkDetailView.as_view(), name='park_detail'), path('/rides/', include('rides.urls', namespace='rides')), ] diff --git a/parks/views.py b/parks/views.py index d7bf5553..c6d19611 100644 --- a/parks/views.py +++ b/parks/views.py @@ -45,24 +45,6 @@ def get_cities(request): ).values_list('name', flat=True)[:10] return JsonResponse(list(cities), safe=False) -def get_locations(request): - query = request.GET.get('q', '') - locations = set() - - # Search countries - countries = Country.objects.filter(name__icontains=query).values_list('name', flat=True)[:5] - locations.update(countries) - - # Search regions - regions = Region.objects.filter(name__icontains=query).values_list('name', flat=True)[:5] - locations.update(regions) - - # Search cities - cities = City.objects.filter(name__icontains=query).values_list('name', flat=True)[:5] - locations.update(cities) - - return JsonResponse(list(locations), safe=False) - class ParkCreateView(LoginRequiredMixin, CreateView): model = Park form_class = ParkForm @@ -163,26 +145,27 @@ class ParkListView(ListView): def get_queryset(self): queryset = Park.objects.select_related('owner', 'country', 'region', 'city').prefetch_related('photos', 'rides') - search = self.request.GET.get('search', '').strip() or None - location = self.request.GET.get('location', '').strip() or None - status = self.request.GET.get('status', '').strip() or None + search = self.request.GET.get('search', '').strip() + country = self.request.GET.get('country', '').strip() + region = self.request.GET.get('region', '').strip() + city = self.request.GET.get('city', '').strip() + status = self.request.GET.get('status', '').strip() if search: queryset = queryset.filter( Q(name__icontains=search) | - Q(location__icontains=search) | - Q(country__name__icontains=search) | - Q(region__name__icontains=search) | - Q(city__name__icontains=search) - ) - if location: - # Try to match against the formatted location or any location field - queryset = queryset.filter( - Q(location__icontains=location) | - Q(country__name__icontains=location) | - Q(region__name__icontains=location) | - Q(city__name__icontains=location) + Q(location__icontains=search) ) + + if country: + queryset = queryset.filter(country__name__icontains=country) + + if region: + queryset = queryset.filter(region__name__icontains=region) + + if city: + queryset = queryset.filter(city__name__icontains=city) + if status: queryset = queryset.filter(status=status) @@ -192,7 +175,9 @@ class ParkListView(ListView): context = super().get_context_data(**kwargs) context['current_filters'] = { 'search': self.request.GET.get('search', ''), - 'location': self.request.GET.get('location', ''), + 'country': self.request.GET.get('country', ''), + 'region': self.request.GET.get('region', ''), + 'city': self.request.GET.get('city', ''), 'status': self.request.GET.get('status', '') } return context diff --git a/static/css/tailwind.css b/static/css/tailwind.css index 6b64f5d3..2ecdd300 100644 --- a/static/css/tailwind.css +++ b/static/css/tailwind.css @@ -3491,6 +3491,10 @@ select { grid-template-columns: repeat(4, minmax(0, 1fr)); } + .lg\:grid-cols-5 { + grid-template-columns: repeat(5, minmax(0, 1fr)); + } + .lg\:text-6xl { font-size: 3.75rem; line-height: 1; diff --git a/templates/parks/park_detail.html b/templates/parks/park_detail.html index 83fc8984..45be2302 100644 --- a/templates/parks/park_detail.html +++ b/templates/parks/park_detail.html @@ -18,8 +18,7 @@ data-field-name="name">{{ park.name }}

- {{ park.location }} + {{ park.get_formatted_location }}

@@ -201,12 +200,10 @@
- Country + Location
-
- {{ park.get_country_name }} +
+ {{ park.get_formatted_location }}
{% if park.opening_date %} diff --git a/templates/parks/park_list.html b/templates/parks/park_list.html index 50f5c05d..7d6ca276 100644 --- a/templates/parks/park_list.html +++ b/templates/parks/park_list.html @@ -16,9 +16,9 @@
-
@@ -29,11 +29,25 @@ placeholder="Search parks...">
- - Country + + placeholder="Select country..."> +
+
+ + +
+
+ +
@@ -84,27 +98,79 @@ {% endblock %} diff --git a/templates/parks/partials/park_list.html b/templates/parks/partials/park_list.html index 9962749f..d6f8e286 100644 --- a/templates/parks/partials/park_list.html +++ b/templates/parks/partials/park_list.html @@ -18,7 +18,7 @@

- {{ park.location }} + {{ park.get_formatted_location }}