title: Latest entry of every month
body: <p>I have a model with a time_stamp (DateTime field) and I want to get the latest entry of every month.</p>
  
  <p>How can I approach this problem?</p>
  
  <p>Model:</p>
  
  <pre><code>class Transaction (models.Model):
      transaction_id = models.AutoField(primary_key=True)
      net_monthly_transaction = models.DecimalField(max_digits = 10, decimal_places = 2, default=0)
      # deposit or withdrawal (withdrawal with negative value)
      amount = models.DecimalField(max_digits = 10, decimal_places = 2)
      time_stamp = models.DateTimeField(default=datetime.now, blank=True)
  
  
      def __str__(self):              # __unicode__ on Python 2
          return str(self.time_stamp)  + str(self.amount) + str(self.net_monthly_transaction)
  </code></pre>
  
  <p>This can easily be accomplished in mysql which I am familiar with, and there are lots of answers for them in SO, here's an example:</p>
  
  <pre><code>SELECT * FROM table 
  WHERE created_on in 
  (select DISTINCT max(created_on) from table 
  GROUP BY YEAR(created_on), MONTH(created_on))
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/5621842/get-last-record-of-each-month-in-mysql">Get last record of each month in MySQL....?</a></p>
  
  <p>How can I accomplish this in Django? Any help or direction would be appreciated.</p>
  
  <p>Thanks in advance,</p>