managers.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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(
  7. sites=settings.SITE_ID, published=True, published_on__lte=datetime.now
  8. )
  9. def leads(self):
  10. return self.filter(published=True, lead=True, published_on__lte=datetime.now)
  11. def nonleads(self):
  12. return self.filter(published=True, lead=False, published_on__lte=datetime.now)
  13. def drafts(self):
  14. return self.filter(sites=settings.SITE_ID, published=False)
  15. class EditorialManager(models.Manager):
  16. def published(self):
  17. return self.filter(
  18. sites=settings.SITE_ID, published=True, published_on__lte=datetime.now
  19. )
  20. def drafts(self):
  21. return self.filter(sites=settings.SITE_ID, published=False)
  22. class EditionManager(models.Manager):
  23. def published(self):
  24. return self.filter(
  25. site=settings.SITE_ID, published=True, published_on__lte=datetime.now
  26. )
  27. class LeadStoryManager(models.Manager):
  28. def get_query_set(self):
  29. return (
  30. super(LeadStoryManager, self)
  31. .get_query_set()
  32. .filter(lead=True, published=True)
  33. )
  34. class PatriotEditionManager(models.Manager):
  35. def get_query_set(self):
  36. return (
  37. super(PatriotEditionManager, self)
  38. .get_query_set()
  39. .filter(paper__name="Castine Patriot", published=True)
  40. )
  41. class AdvantagesEditionManager(models.Manager):
  42. def get_query_set(self):
  43. return (
  44. super(AdvantagesEditionManager, self)
  45. .get_query_set()
  46. .filter(paper__name="Island Ad-Vantages", published=True)
  47. )
  48. class PacketEditionManager(models.Manager):
  49. def get_query_set(self):
  50. return (
  51. super(PacketEditionManager, self)
  52. .get_query_set()
  53. .filter(paper__name="Weekly Packet", published=True)
  54. )
  55. class CompassEditionManager(models.Manager):
  56. def get_query_set(self):
  57. return (
  58. super(CompassEditionManager, self)
  59. .get_query_set()
  60. .filter(paper__name="Compass", published=True)
  61. )