Date/time range filters - Flask-Admin
Flask-Admin’s date and datetime filters used bootstrap-datetimepicker, and it was giving me trouble on Bootstrap 3. I swapped it for bootstrap-daterangepicker (#688), which bundles a date picker, a time picker, and a datetime picker in one library and works on both Bootstrap 2 and 3.
With the new picker in place I added range filters for date, datetime, and time columns on the SQLAlchemy backend (#703). Instead of just “greater than” or “less than”, you can filter for records that fall between two dates, or two times.
class EventView(ModelView):
column_filters = ['start_time', 'created_at']
Pick the “between” option on one of those columns and you get a two-ended picker.
While I was in there I moved the active-filter rendering into filters.js. It had been split between models/layout.html and the JS, and adding range filters would have meant duplicating that generation logic in the template. Loading the filters entirely from filters.js kept it in one place.
One follow-up: the “equals” filter on time and datetime columns was matching nothing on SQLite, because of how SQLite stores timestamps (#697).