title: SQLAlchemy: How to group by two fields and filter by date
body: <p>So I have a table with a datestamp and two fields that I want to make sure that they are unique in the last month.</p>
  
  <pre><code>table.id
  table.datestamp
  table.field1
  table.field2
  </code></pre>
  
  <p>There should be no duplicate record with the same field1 + 2 compound value in the last month.</p>
  
  <p>The steps in my head are:</p>
  
  <ol>
  <li>Group by the two fields</li>
  <li>Look back over the last month's data to make sure this unique grouping doesn't occur.</li>
  </ol>
  
  <p>I've got this far, but I don't think this works:</p>
  
  <pre><code>result = session.query(table).group_by(\
      table.field1,
      table.field2,
      func.month(table.timestamp))
  </code></pre>
  
  <p>But I'm unsure how to do this in sqlalchemy. Could someone advise me?</p>
  
  <p>Thanks very much!</p>