Adding News app!

This commit is contained in:
Víðir Valberg Guðmundsson 2016-05-30 21:36:14 +02:00 committed by Víðir Valberg Guðmundsson
parent ef1d306617
commit e8bda33ac3
14 changed files with 117 additions and 0 deletions

View file

@ -27,6 +27,7 @@ INSTALLED_APPS = [
'profiles',
'camps',
'shop',
'news',
'allauth',
'allauth.account',

View file

@ -52,6 +52,7 @@
{% endif %}
{% endif %}
<li><a href="{% url 'news:index' %}">News</a></li>
<li><a href="{% url 'good-to-know' %}">Info</a></li>
<li><a href="{% url 'contact' %}">Contact</a></li>
{% if user.is_authenticated %}

View file

@ -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)),

0
news/__init__.py Normal file
View file

9
news/admin.py Normal file
View file

@ -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']

7
news/apps.py Normal file
View file

@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class NewsConfig(AppConfig):
name = 'news'

9
news/managers.py Normal file
View file

@ -0,0 +1,9 @@
from django.db.models import QuerySet
class NewsItemQuerySet(QuerySet):
def public(self):
return self.filter(
public=True
)

View file

@ -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,
},
),
]

View file

21
news/models.py Normal file
View file

@ -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()

View file

@ -0,0 +1,15 @@
{% extends 'base.html' %}
{% block content %}
{% for item in news_items %}
<div>
<h3>{{ item.title }} <small>{{ item.published_at|date:"Y-m-d" }}</small></h3>
</div>
{{ item.content }}
{% if not forloop.last %}
<hr />
{% endif %}
{% empty %}
<h3>No news yet. Stay tuned!</h3>
{% endfor %}
{% endblock %}

3
news/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
news/urls.py Normal file
View file

@ -0,0 +1,7 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.NewsIndex.as_view(), name='index'),
]

9
news/views.py Normal file
View file

@ -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'