mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:31:08 -05:00
76 lines
2.6 KiB
Markdown
76 lines
2.6 KiB
Markdown
# Park Search Integration
|
|
|
|
## Overview
|
|
Integrated the parks app with the site-wide search system to provide consistent filtering and search capabilities across the platform.
|
|
|
|
## Implementation Details
|
|
|
|
### 1. Filter Configuration
|
|
```python
|
|
# parks/filters.py
|
|
ParkFilter = create_model_filter(
|
|
model=Park,
|
|
search_fields=['name', 'description', 'location__city', 'location__state', 'location__country'],
|
|
mixins=[LocationFilterMixin, RatingFilterMixin, DateRangeFilterMixin],
|
|
additional_filters={
|
|
'status': {
|
|
'field_class': 'django_filters.ChoiceFilter',
|
|
'field_kwargs': {'choices': Park._meta.get_field('status').choices}
|
|
},
|
|
'opening_date': {
|
|
'field_class': 'django_filters.DateFromToRangeFilter',
|
|
},
|
|
'owner': {
|
|
'field_class': 'django_filters.ModelChoiceFilter',
|
|
'field_kwargs': {'queryset': 'companies.Company.objects.all()'}
|
|
},
|
|
'min_rides': {
|
|
'field_class': 'django_filters.NumberFilter',
|
|
'field_kwargs': {'field_name': 'ride_count', 'lookup_expr': 'gte'}
|
|
},
|
|
'min_coasters': {
|
|
'field_class': 'django_filters.NumberFilter',
|
|
'field_kwargs': {'field_name': 'coaster_count', 'lookup_expr': 'gte'}
|
|
},
|
|
'min_size': {
|
|
'field_class': 'django_filters.NumberFilter',
|
|
'field_kwargs': {'field_name': 'size_acres', 'lookup_expr': 'gte'}
|
|
}
|
|
}
|
|
)
|
|
```
|
|
|
|
### 2. View Integration
|
|
- Updated `ParkListView` to use `HTMXFilterableMixin`
|
|
- Configured proper queryset optimization with `select_related` and `prefetch_related`
|
|
- Added pagination support
|
|
- Maintained ride count annotations
|
|
|
|
### 3. Template Structure
|
|
- Created `search/templates/search/partials/park_results.html` for consistent result display
|
|
- Includes:
|
|
- Park image thumbnails
|
|
- Basic park information
|
|
- Location details
|
|
- Status indicators
|
|
- Ride count badges
|
|
- Rating display
|
|
|
|
### 4. Quick Search Support
|
|
- Modified `search_parks` view for dropdown/quick search scenarios
|
|
- Uses the same filter system but with simplified output
|
|
- Limited to 10 results for performance
|
|
- Added location preloading
|
|
|
|
## Benefits
|
|
1. Consistent filtering across the platform
|
|
2. Enhanced search capabilities with location and rating filters
|
|
3. Improved performance through proper query optimization
|
|
4. Better maintainability using the site-wide search system
|
|
5. HTMX-powered dynamic updates
|
|
|
|
## Technical Notes
|
|
- Uses django-filter backend
|
|
- Integrates with location and rating mixins
|
|
- Supports both full search and quick search use cases
|
|
- Maintains existing functionality while improving code organization |