# Ride Count Field Implementation ## Context While implementing park views, we encountered an error where a `ride_count` annotation conflicted with an existing model field of the same name. This raised a question about how to handle real-time ride counts versus stored counts. ## Decision We decided to use both approaches but with distinct names: 1. **Model Field (`ride_count`)**: - Kept the original field for backward compatibility - Used in test fixtures and filtering system - Can serve as a cached/denormalized value 2. **Annotation (`current_ride_count`)**: - Added new annotation with a distinct name - Provides real-time count of rides - Used in templates for display purposes This approach allows us to: - Maintain existing functionality in tests and filters - Show accurate, real-time counts in the UI - Avoid name conflicts between fields and annotations ## Implementation - Kept the `ride_count` IntegerField in the Park model - Added `current_ride_count = Count('rides', distinct=True)` annotation in views - Updated templates to use `current_ride_count` for display ## Future Considerations We might want to: 1. Add a periodic task to sync the stored `ride_count` with the computed value 2. Consider deprecating the stored field if it's not needed for performance 3. Add validation to ensure the stored count stays in sync with reality ## Related Files - parks/models.py - parks/views.py - parks/templates/parks/partials/park_list_item.html - parks/tests/test_filters.py