Minimal news app
This commit is contained in:
parent
6ed705c0f5
commit
e684ac24e9
|
@ -1,12 +1,4 @@
|
||||||
"""
|
""" Django settings for idre project. """
|
||||||
Django settings for idre project.
|
|
||||||
|
|
||||||
For more information on this file, see
|
|
||||||
https://docs.djangoproject.com/en/1.7/topics/settings/
|
|
||||||
|
|
||||||
For the full list of settings and their values, see
|
|
||||||
https://docs.djangoproject.com/en/1.7/ref/settings/
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -33,7 +25,8 @@ INSTALLED_APPS = (
|
||||||
"django.contrib.sessions",
|
"django.contrib.sessions",
|
||||||
"django.contrib.messages",
|
"django.contrib.messages",
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
"label"
|
"label",
|
||||||
|
"news"
|
||||||
)
|
)
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE_CLASSES = (
|
||||||
|
|
12
idre/urls.py
12
idre/urls.py
|
@ -5,16 +5,18 @@ from django.contrib import admin
|
||||||
import idre.settings
|
import idre.settings
|
||||||
import idre.views
|
import idre.views
|
||||||
import label.urls
|
import label.urls
|
||||||
|
import news.urls
|
||||||
|
|
||||||
|
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = (
|
||||||
url(r"^$", idre.views.home, name = "home")
|
[ url(r"^(?:about/)?$", idre.views.about_view, name = "about") ] +
|
||||||
] + label.urls.urlpatterns + [
|
label.urls.urlpatterns +
|
||||||
url(r"^admin/", include(admin.site.urls))
|
news.urls.urlpatterns +
|
||||||
]
|
[ url(r"^admin/", include(admin.site.urls)) ]
|
||||||
|
)
|
||||||
|
|
||||||
if idre.settings.DEBUG:
|
if idre.settings.DEBUG:
|
||||||
urlpatterns += static(
|
urlpatterns += static(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
def home(request):
|
def about_view(request):
|
||||||
return render(request, "idre/home.html")
|
return render(request, "about.html")
|
||||||
|
|
0
news/__init__.py
Normal file
0
news/__init__.py
Normal file
6
news/admin.py
Normal file
6
news/admin.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from news.models import Article
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Article)
|
5
news/apps.py
Normal file
5
news/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class NewsConfig(AppConfig):
|
||||||
|
name = "news"
|
29
news/migrations/0001_initial.py
Normal file
29
news/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9.1 on 2016-02-01 19:25
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Article',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('title', models.CharField(max_length=256)),
|
||||||
|
('content', models.TextField(help_text='Markdown formatting supported')),
|
||||||
|
('author', models.CharField(max_length=64)),
|
||||||
|
('date', models.DateField()),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'ordering': ('date',),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
0
news/migrations/__init__.py
Normal file
0
news/migrations/__init__.py
Normal file
15
news/models.py
Normal file
15
news/models.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
ARTICLE_CONTENT_HINT = "Markdown formatting supported"
|
||||||
|
|
||||||
|
class Article(models.Model):
|
||||||
|
""" News article. """
|
||||||
|
|
||||||
|
title = models.CharField(max_length = 256)
|
||||||
|
content = models.TextField(help_text = ARTICLE_CONTENT_HINT)
|
||||||
|
author = models.CharField(max_length = 64)
|
||||||
|
date = models.DateField()
|
||||||
|
|
||||||
|
class Meta(object):
|
||||||
|
ordering = ("date",)
|
29
news/templates/news/news.html
Normal file
29
news/templates/news/news.html
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block stylesheets %}
|
||||||
|
<link rel="stylesheet" href="{% static 'css/news.css' %}" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<section id="news">
|
||||||
|
|
||||||
|
{% for article in articles %}
|
||||||
|
<article>
|
||||||
|
<p class="article_header">
|
||||||
|
<span class="title">{{ article.title }}</span>
|
||||||
|
<span class="author">{{ article.author }}</span>,
|
||||||
|
<span class="date">{{ article.date }}</span>
|
||||||
|
</p>
|
||||||
|
{% autoescape off %}
|
||||||
|
{{ article.content }}
|
||||||
|
{% endautoescape %}
|
||||||
|
</article>
|
||||||
|
{% if not forloop.last %}<hr />{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
8
news/urls.py
Normal file
8
news/urls.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
import news.views
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r"^news/$", news.views.articles_view, name = "news"),
|
||||||
|
]
|
12
news/views.py
Normal file
12
news/views.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
import markdown
|
||||||
|
|
||||||
|
from news.models import Article
|
||||||
|
|
||||||
|
|
||||||
|
def articles_view(request):
|
||||||
|
articles = Article.objects.all().order_by("date").reverse()
|
||||||
|
for article in articles:
|
||||||
|
article.content = markdown.markdown(article.content)
|
||||||
|
context = { "articles": articles }
|
||||||
|
return render(request, "news/news.html", context)
|
22
static/css/news.css
Normal file
22
static/css/news.css
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#news article .title {
|
||||||
|
font-size: 1.2em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
#news article .author,
|
||||||
|
#news article .date {
|
||||||
|
font-style: oblique;
|
||||||
|
}
|
||||||
|
|
||||||
|
#news hr {
|
||||||
|
border-color: #929292 -moz-use-text-color -moz-use-text-color;
|
||||||
|
border-right: 0px none;
|
||||||
|
border-style: solid none none;
|
||||||
|
border-width: 1px 0px 0px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
margin-top: 20px;
|
||||||
|
-moz-border-bottom-colors: none;
|
||||||
|
-moz-border-left-colors: none;
|
||||||
|
-moz-border-right-colors: none;
|
||||||
|
-moz-border-top-colors: none;
|
||||||
|
}
|
|
@ -23,8 +23,10 @@
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
|
<a href="/news/">news</a> |
|
||||||
<a href="/artists/">artists</a> |
|
<a href="/artists/">artists</a> |
|
||||||
<a href="/releases/">releases</a>
|
<a href="/releases/">releases</a> |
|
||||||
|
<a href="/about/">about</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<section id="content">
|
<section id="content">
|
Loading…
Reference in a new issue