managers.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from datetime import datetime
  2. from django.db import models
  3. from django.conf import settings
  4. class StoryManager(models.Manager):
  5. def published(self):
  6. return self.filter(sites=settings.SITE_ID, published=True, published_on__lte=datetime.now)
  7. def leads(self):
  8. return self.filter(published=True, lead=True, published_on__lte=datetime.now)
  9. def nonleads(self):
  10. return self.filter(published=True, lead=False, published_on__lte=datetime.now)
  11. def drafts(self):
  12. return self.filter(sites=settings.SITE_ID, published=False)
  13. class EditorialManager(models.Manager):
  14. def published(self):
  15. return self.filter(sites=settings.SITE_ID, published=True, published_on__lte=datetime.now)
  16. def drafts(self):
  17. return self.filter(sites=settings.SITE_ID, published=False)
  18. class EditionManager(models.Manager):
  19. def published(self):
  20. return self.filter(site=settings.SITE_ID, published=True, published_on__lte=datetime.now)
  21. class LeadStoryManager(models.Manager):
  22. def get_query_set(self):
  23. return super(LeadStoryManager, self).get_query_set().filter(lead=True, published=True)
  24. class PatriotEditionManager(models.Manager):
  25. def get_query_set(self):
  26. return super(PatriotEditionManager, self).get_query_set().filter(paper__name="Castine Patriot", published=True)
  27. class AdvantagesEditionManager(models.Manager):
  28. def get_query_set(self):
  29. return super(AdvantagesEditionManager, self).get_query_set().filter(paper__name="Island Ad-Vantages", published=True)
  30. class PacketEditionManager(models.Manager):
  31. def get_query_set(self):
  32. return super(PacketEditionManager, self).get_query_set().filter(paper__name="Weekly Packet", published=True)
  33. class CompassEditionManager(models.Manager):
  34. def get_query_set(self):
  35. return super(CompassEditionManager, self).get_query_set().filter(paper__name="Compass", published=True)