Mercurial > public > bravenewsurf
changeset 14:2de51cc51d3a
My first stab at the news app. The template is a little dull, but it's a start.
author | Bob Mourlam <bob.mourlam@gmail.com> |
---|---|
date | Sun, 30 Oct 2011 21:33:45 -0500 |
parents | 40d86ae48db1 |
children | 6b664ec90f2f |
files | bns_website/bands/admin.py bns_website/news/__init__.py bns_website/news/models.py bns_website/news/tests.py bns_website/news/views.py bns_website/settings/base.py bns_website/templates/core/navbar_tag.html bns_website/templates/news/news_list.html bns_website/urls.py |
diffstat | 8 files changed, 77 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/bns_website/bands/admin.py Sun Oct 30 18:29:41 2011 -0500 +++ b/bns_website/bands/admin.py Sun Oct 30 21:33:45 2011 -0500 @@ -4,11 +4,12 @@ """ from django.contrib import admin from bands.models import Band +from news.models import News class BandAdmin(admin.ModelAdmin): list_display = ['name', 'url', 'order'] list_editable = ['order'] - admin.site.register(Band, BandAdmin) +admin.site.register(News)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bns_website/news/models.py Sun Oct 30 21:33:45 2011 -0500 @@ -0,0 +1,21 @@ +from django.db import models + +# Create your models here. +class News(models.Model): + """ + This model represents all the info we store about each news entry. + + """ + title = models.CharField(max_length=128) + date = models.DateTimeField() + content = models.TextField() + + # User field? + + + + class Meta: + verbose_name_plural="News" + + def __unicode__(self): + return self.title
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bns_website/news/tests.py Sun Oct 30 21:33:45 2011 -0500 @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bns_website/news/views.py Sun Oct 30 21:33:45 2011 -0500 @@ -0,0 +1,1 @@ +# Create your views here.
--- a/bns_website/settings/base.py Sun Oct 30 18:29:41 2011 -0500 +++ b/bns_website/settings/base.py Sun Oct 30 21:33:45 2011 -0500 @@ -135,6 +135,7 @@ 'django.contrib.admindocs', 'core', 'bands', + 'news', ] # A sample logging configuration. The only tangible logging
--- a/bns_website/templates/core/navbar_tag.html Sun Oct 30 18:29:41 2011 -0500 +++ b/bns_website/templates/core/navbar_tag.html Sun Oct 30 21:33:45 2011 -0500 @@ -5,7 +5,7 @@ <a class="brand" href="{% url 'home' %}">Brave New Surf</a> <ul class="nav"> <li{% if active_tab == "home" %} class="active"{% endif %}><a href="{% url 'home' %}">Home</a></li> -<li{% if active_tab == "news" %} class="active"{% endif %}><a href="#">News</a></li> +<li{% if active_tab == "news" %} class="active"{% endif %}><a href="{% url 'news' %}">News</a></li> <li{% if active_tab == "reviews" %} class="active"{% endif %}><a href="#">Reviews</a></li> <li{% if active_tab == "bands" %} class="active"{% endif %}><a href="{% url 'bands' %}">Bands</a></li> <li{% if active_tab == "music" %} class="active"{% endif %}><a href="{% url 'music' %}">Listen</a></li>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bns_website/templates/news/news_list.html Sun Oct 30 21:33:45 2011 -0500 @@ -0,0 +1,31 @@ +{% extends 'base.html' %} +{% load core_tags %} +{% block title %}News{% endblock %} + +{% block custom_css %} +<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css"> +{% endblock %} +{% block custom_js %} +<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> +<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> +<script type="text/javascript"> + $(function() { + $("#accordion").accordion({active: false}); + }); +</script> +{% endblock %} + +{% block content %} +{% navbar 'news' %} +<h1>News</h1> +<dl> +{% for news in object_list %} +<dt>{{ news.title }}</a></dt> +<dd>{{ news.content|linebreaksbr }}</dd> +<p/> +{% endfor %} +</dl> + +</div> + +{% endblock %}
--- a/bns_website/urls.py Sun Oct 30 18:29:41 2011 -0500 +++ b/bns_website/urls.py Sun Oct 30 21:33:45 2011 -0500 @@ -4,6 +4,7 @@ from django.views.generic import ListView from bands.models import Band +from news.models import News admin.autodiscover() @@ -14,6 +15,9 @@ url(r'^bands/$', ListView.as_view(model=Band), name="bands"), + url(r'^news/$', + ListView.as_view(model=News), + name="news"), url(r'^listen/$', TemplateView.as_view(template_name="music.html"), name="music"),