Announcement
This commit is contained in:
parent
66547f27e7
commit
776573d4a9
3 changed files with 60 additions and 0 deletions
33
src/c3nav/site/migrations/0001_announcement.py
Normal file
33
src/c3nav/site/migrations/0001_announcement.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-07 22:51
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import c3nav.mapdata.fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Announcement',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(auto_now_add=True, verbose_name='created')),
|
||||
('active_until', models.DateTimeField(null=True, verbose_name='active until')),
|
||||
('active', models.BooleanField(default=True, verbose_name='active')),
|
||||
('message', c3nav.mapdata.fields.I18nField(verbose_name='Message')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Announcement',
|
||||
'verbose_name_plural': 'Announcements',
|
||||
'get_latest_by': 'created',
|
||||
'default_related_name': 'announcements',
|
||||
},
|
||||
),
|
||||
]
|
0
src/c3nav/site/migrations/__init__.py
Normal file
0
src/c3nav/site/migrations/__init__.py
Normal file
27
src/c3nav/site/models.py
Normal file
27
src/c3nav/site/models.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from c3nav.mapdata.fields import I18nField
|
||||
|
||||
|
||||
class Announcement(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True, verbose_name=_('created'))
|
||||
active_until = models.DateTimeField(null=True, verbose_name=_('active until'))
|
||||
active = models.BooleanField(default=True, verbose_name=_('active'))
|
||||
message = I18nField(_('Message'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Announcement')
|
||||
verbose_name_plural = _('Announcements')
|
||||
default_related_name = 'announcements'
|
||||
get_latest_by = 'created'
|
||||
|
||||
@classmethod
|
||||
def get_current(cls):
|
||||
try:
|
||||
return cls.objects.filter(Q(active=True) & (Q(active_until__isnull=True) |
|
||||
Q(active_until__isnull=timezone.now()))).latest()
|
||||
except cls.DoesNotExist:
|
||||
return None
|
Loading…
Add table
Add a link
Reference in a new issue