2021-05-19 20:56:00 +00:00
|
|
|
""" admin announcements """
|
|
|
|
from django.db import models
|
2021-05-19 22:17:32 +00:00
|
|
|
from django.db.models import Q
|
2021-05-19 20:56:00 +00:00
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from .base_model import BookWyrmModel
|
|
|
|
|
|
|
|
|
|
|
|
class Announcement(BookWyrmModel):
|
|
|
|
"""The admin has something to say"""
|
|
|
|
|
|
|
|
user = models.ForeignKey("User", on_delete=models.PROTECT)
|
|
|
|
preview = models.CharField(max_length=255)
|
2021-05-20 19:36:42 +00:00
|
|
|
content = models.TextField(null=True, blank=True)
|
2021-05-19 20:56:00 +00:00
|
|
|
event_date = models.DateTimeField(blank=True, null=True)
|
|
|
|
start_date = models.DateTimeField(blank=True, null=True)
|
|
|
|
end_date = models.DateTimeField(blank=True, null=True)
|
|
|
|
active = models.BooleanField(default=True)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def active_announcements(cls):
|
|
|
|
"""announcements that should be displayed"""
|
|
|
|
now = timezone.now()
|
2021-05-19 22:17:32 +00:00
|
|
|
return cls.objects.filter(
|
|
|
|
Q(start_date__isnull=True) | Q(start_date__lte=now),
|
|
|
|
Q(end_date__isnull=True) | Q(end_date__gte=now),
|
|
|
|
active=True,
|
|
|
|
)
|