diff --git a/bornhack/settings/base.py b/bornhack/settings/base.py index 67a5098b..ab56fd63 100644 --- a/bornhack/settings/base.py +++ b/bornhack/settings/base.py @@ -27,6 +27,7 @@ INSTALLED_APPS = [ 'profiles', 'camps', 'shop', + 'news', 'allauth', 'allauth.account', diff --git a/bornhack/templates/base.html b/bornhack/templates/base.html index 905657f7..b8f18659 100644 --- a/bornhack/templates/base.html +++ b/bornhack/templates/base.html @@ -52,6 +52,7 @@ {% endif %} {% endif %} +
  • News
  • Info
  • Contact
  • {% if user.is_authenticated %} diff --git a/bornhack/urls.py b/bornhack/urls.py index 72e96c04..d85a7fed 100644 --- a/bornhack/urls.py +++ b/bornhack/urls.py @@ -44,6 +44,10 @@ urlpatterns = [ r'^shop/', include('shop.urls', namespace='shop') ), + url( + r'^news/', + include('news.urls', namespace='news') + ), url(r'^accounts/', include('allauth.urls')), url(r'^admin/', include(admin.site.urls)), diff --git a/news/__init__.py b/news/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/news/admin.py b/news/admin.py new file mode 100644 index 00000000..587c9ff9 --- /dev/null +++ b/news/admin.py @@ -0,0 +1,9 @@ +from django.contrib import admin + +from . import models + + +@admin.register(models.NewsItem) +class NewsItemModelAdmin(admin.ModelAdmin): + list_display = ['title', 'public', 'published_at'] + list_filter = ['public'] diff --git a/news/apps.py b/news/apps.py new file mode 100644 index 00000000..de4f85fc --- /dev/null +++ b/news/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class NewsConfig(AppConfig): + name = 'news' diff --git a/news/managers.py b/news/managers.py new file mode 100644 index 00000000..f4ee7415 --- /dev/null +++ b/news/managers.py @@ -0,0 +1,9 @@ +from django.db.models import QuerySet + + +class NewsItemQuerySet(QuerySet): + + def public(self): + return self.filter( + public=True + ) diff --git a/news/migrations/0001_initial.py b/news/migrations/0001_initial.py new file mode 100644 index 00000000..12659c44 --- /dev/null +++ b/news/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-30 19:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='NewsItem', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('title', models.CharField(max_length=100)), + ('content', models.TextField()), + ('public', models.BooleanField(default=False)), + ('published_at', models.DateTimeField()), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/news/migrations/__init__.py b/news/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/news/models.py b/news/models.py new file mode 100644 index 00000000..df577b53 --- /dev/null +++ b/news/models.py @@ -0,0 +1,21 @@ +from __future__ import unicode_literals + +from django.db import models + +from bornhack.utils import CreatedUpdatedModel +from news.managers import NewsItemQuerySet + + +class NewsItem(CreatedUpdatedModel): + class Meta: + ordering = ['-published_at'] + + title = models.CharField(max_length=100) + content = models.TextField() + public = models.BooleanField(default=False) + published_at = models.DateTimeField() + + def __str__(self): + return self.title + + objects = NewsItemQuerySet.as_manager() diff --git a/news/templates/news_index.html b/news/templates/news_index.html new file mode 100644 index 00000000..49440d98 --- /dev/null +++ b/news/templates/news_index.html @@ -0,0 +1,15 @@ +{% extends 'base.html' %} + +{% block content %} +{% for item in news_items %} +
    +

    {{ item.title }} {{ item.published_at|date:"Y-m-d" }}

    +
    + {{ item.content }} + {% if not forloop.last %} +
    + {% endif %} +{% empty %} +

    No news yet. Stay tuned!

    +{% endfor %} +{% endblock %} \ No newline at end of file diff --git a/news/tests.py b/news/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/news/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/news/urls.py b/news/urls.py new file mode 100644 index 00000000..9f1c4708 --- /dev/null +++ b/news/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url +from . import views + + +urlpatterns = [ + url(r'^$', views.NewsIndex.as_view(), name='index'), +] diff --git a/news/views.py b/news/views.py new file mode 100644 index 00000000..1afd6c21 --- /dev/null +++ b/news/views.py @@ -0,0 +1,9 @@ +from django.views.generic import ListView +from . import models + + +class NewsIndex(ListView): + model = models.NewsItem + queryset = models.NewsItem.objects.public() + template_name = 'news_index.html' + context_object_name = 'news_items'