mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 11:31:07 -05:00
idk man
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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)
|
||||
|
||||
@@ -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('<slug:slug>/', views.ParkDetailView.as_view(), name='park_detail'),
|
||||
path('<slug:park_slug>/rides/', include('rides.urls', namespace='rides')),
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user