title: Flask-SqlAlchemy Filtering by time section of datetime
body: <p>I am looking to filter by the time section of a datetime column in Flask-Admin using Flask-SQlAlchemy.</p>
  <p>My attempt so far is:</p>
  <pre><code>class BaseTimeBetweenFilter(filters.TimeBetweenFilter):
      def apply(self, query, value, alias=None):
          return query.filter(cast(Doctor.datetime, Time) &gt;= value[0],
                cast(Doctor.datetime, Time) &lt;= value[1]).all()
  </code></pre>
  <p>I've got the time selector showing and if I do</p>
  <pre><code>print (value[0])
  </code></pre>
  <p>or</p>
  <pre><code>print (value[1])
  </code></pre>
  <p>it prints out the inputted times as expected. However the query is not working.</p>
  <blockquote>
  <p>admin-panel_1  |     response = self.full_dispatch_request()</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask/app.py&quot;, line 1641, in full_dispatch_request</p>
  <p>admin-panel_1  |     rv = self.handle_user_exception(e)</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask/app.py&quot;, line 1544, in handle_user_exception</p>
  <p>admin-panel_1  |     reraise(exc_type, exc_value, tb)</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask/_compat.py&quot;, line 33, in reraise</p>
  <p>admin-panel_1  |     raise value</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask/app.py&quot;, line 1639, in full_dispatch_request</p>
  <p>admin-panel_1  |     rv = self.dispatch_request()</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask/app.py&quot;, line 1625, in dispatch_request</p>
  <p>admin-panel_1  |     return self.view_functionsrule.endpoint</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask_admin/base.py&quot;, line 69, in inner</p>
  <p>admin-panel_1  |     return self._run_view(f, *args, **kwargs)</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask_admin/base.py&quot;, line 368, in _run_view</p>
  <p>admin-panel_1  |     return fn(self, *args, **kwargs)</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask_admin/model/base.py&quot;, line 1818, in index_view</p>
  <p>admin-panel_1  |     view_args.search, view_args.filters)</p>
  <p>admin-panel_1  |   File &quot;/usr/local/lib/python3.5/dist-packages/flask_admin/contrib/sqla/view.py&quot;, line 975, in get_list</p>
  <p>admin-panel_1  |     count = count_query.scalar() if count_query else None</p>
  <p>admin-panel_1  | AttributeError: 'list' object has no attribute 'scalar'</p>
  </blockquote>
  <p>Also, I import Time and Cast from sqlalchemy, is this OK or should I be getting it from flask-sqlalchemy?</p>
  <pre><code>from flask_sqlalchemy import SQLAlchemy
  from sqlalchemy import Time, cast
  </code></pre>