Skip to content

Instantly share code, notes, and snippets.

@craigds
Created February 24, 2011 20:33
Show Gist options
  • Save craigds/842832 to your computer and use it in GitHub Desktop.
Save craigds/842832 to your computer and use it in GitHub Desktop.
# sample code as a suggestion for https://convore.com/django-community/how-to-make-an-automatic-status-change/
from datetime import datetime
class MyManager(models.Manager):
def active(self):
return self.get_query_set().filter(expires_at__gt=datetime.now())
class MyClass(models.Model):
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
expires_at = models.DateTimeField(db_index=True)
@property
def active(self):
return self.expires_at > datetime.now()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment