Commit 6ad4a5c9 authored by Sli's avatar Sli

Ajout du système de pages

parent 915f2289
......@@ -3,8 +3,9 @@ from django.contrib import admin
from markdownx.models import MarkdownxField
from markdownx.widgets import AdminMarkdownxWidget
from ordered_model.admin import OrderedModelAdmin
from .models import Article
from .models import Article, Page
class ArticleAdmin(admin.ModelAdmin):
......@@ -15,6 +16,17 @@ class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'published', 'date')
list_editable = ('title', 'published')
ordering = ('-date', )
search_fields = ['title', 'content']
search_fields = ['title', 'content', 'date']
class PageAdmin(OrderedModelAdmin):
formfield_overrides = {
MarkdownxField: {'widget': AdminMarkdownxWidget},
}
list_display = ('title', 'published', 'date', 'move_up_down_links')
list_editable = ('title', 'published')
search_fields = ['title', 'content', 'date']
admin.site.register(Article, ArticleAdmin)
admin.site.register(Page, PageAdmin)
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-04 22:32
# Generated by Django 1.9.7 on 2016-06-06 20:36
from __future__ import unicode_literals
from django.db import migrations, models
import markdownx.models
class Migration(migrations.Migration):
......@@ -17,10 +18,22 @@ class Migration(migrations.Migration):
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('title', models.CharField(max_length=100, verbose_name='Titre')),
('slug', models.SlugField(editable=False, max_length=150, unique=True)),
('content', models.TextField()),
('published', models.BooleanField(default=False)),
('content', markdownx.models.MarkdownxField(verbose_name='Contenu')),
('published', models.BooleanField(default=False, verbose_name='Publication')),
('date', models.DateTimeField(auto_now_add=True, verbose_name='Date de parution')),
],
),
migrations.CreateModel(
name='Page',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100, verbose_name='Titre')),
('slug', models.SlugField(editable=False, max_length=150, unique=True)),
('content', markdownx.models.MarkdownxField(verbose_name='Contenu')),
('published', models.BooleanField(default=False, verbose_name='Publication')),
('date', models.DateTimeField(auto_now_add=True, verbose_name='Date de parution')),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-04 23:32
from __future__ import unicode_literals
from django.db import migrations
import markdownx.models
class Migration(migrations.Migration):
dependencies = [
('blog', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='article',
name='content',
field=markdownx.models.MarkdownxField(),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-05 16:31
# Generated by Django 1.9.7 on 2016-06-06 20:40
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
from django.utils.timezone import utc
class Migration(migrations.Migration):
dependencies = [
('blog', '0002_auto_20160604_2332'),
('blog', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='page',
options={'ordering': ('order',)},
),
migrations.AddField(
model_name='article',
name='date',
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2016, 6, 5, 16, 31, 46, 374730, tzinfo=utc), verbose_name='Date de parution'),
model_name='page',
name='order',
field=models.PositiveIntegerField(db_index=True, default=0, editable=False),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-05 16:34
from __future__ import unicode_literals
from django.db import migrations, models
import markdownx.models
class Migration(migrations.Migration):
dependencies = [
('blog', '0003_article_date'),
]
operations = [
migrations.AlterField(
model_name='article',
name='content',
field=markdownx.models.MarkdownxField(verbose_name='Contenu'),
),
migrations.AlterField(
model_name='article',
name='published',
field=models.BooleanField(default=False, verbose_name='Publication'),
),
migrations.AlterField(
model_name='article',
name='title',
field=models.CharField(max_length=100, verbose_name='Titre'),
),
]
from django.db import models
from django.utils.text import slugify
from ordered_model.models import OrderedModel
from blog.snippets import SlugUnique
from django.core.urlresolvers import reverse
from markdownx.models import MarkdownxField
......@@ -25,3 +25,29 @@ class Article(models.Model):
def get_absolute_url(self):
return reverse('article', args=[self.slug])
class Page(OrderedModel):
"""Page standart"""
title = models.CharField(max_length=100, verbose_name="Titre")
slug = models.SlugField(unique=True, max_length=150, editable=False)
content = MarkdownxField(verbose_name="Contenu")
published = models.BooleanField(default=False, verbose_name="Publication")
date = models.DateTimeField(auto_now_add=True, auto_now=False,
verbose_name="Date de parution")
class Meta(OrderedModel.Meta):
ordering = ('order',)
def __str__(self):
self.bottom()
return self.title
def save(self, *args, **kwargs):
SlugUnique.unique_slugify(self, self.title)
super(Page, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('page', args=[self.slug])
<!DOCTYPE html>
{% load markdown_deux_tags %}
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<h1>{{content.title}}</h1>
{% markdown %}
{{content.content}}
{% endmarkdown %}
</body>
</html>
\ No newline at end of file
......@@ -2,7 +2,7 @@
# @Author: klmp200
# @Date: 2016-06-04 23:24:06
# @Last Modified by: klmp200
# @Last Modified time: 2016-06-06 13:19:24
# @Last Modified time: 2016-06-06 16:33:05
from django.conf.urls import patterns, url
......@@ -10,5 +10,6 @@ urlpatterns = patterns('blog.views',
url(r'^$', 'blog', name='blog'),
url(r'^article/(?P<slug>.+)$', 'article', name='article'),
url(r'^p/(?P<slug>.+)$', 'page', name='page'),
)
\ No newline at end of file
#-*- coding: utf-8 -*-
from django.shortcuts import render, get_object_or_404
from blog.models import Article
from blog.models import Article, Page
def blog(request):
......@@ -14,3 +14,10 @@ def article(request, slug):
article = get_object_or_404(Article, slug=slug, published=True)
return render(request, 'blog/article.html', {'article': article})
def page(request, slug):
content = get_object_or_404(Page, slug, published=True)
return render(request, 'blog/page.html', {'content': content})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment