def count(self):
if self._distinct or self._limits:<EOL><INDENT>sql = u'<STR_LIT>' % self.as_sql()<EOL>raw = self._database.raw(sql)<EOL>return int(raw) if raw else <NUM_LIT:0><EOL><DEDENT>conditions = (self._where_q & self._prewhere_q).to_sql(self._model_cls)<EOL>return self._database.count(self._model_cls, conditions)<EOL>
Returns the number of matching model instances.