From 0b5eb1c3de4b96a048f784ab7c210462f26ac8da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Perrin?= Date: Wed, 28 Sep 2016 22:26:45 +0100 Subject: [PATCH] Add the possibility of attaching notes to an author --- quotes/migrations/0002_author_notes.py | 19 +++++++++++++++++++ quotes/migrations/0003_auto_20160928_2223.py | 19 +++++++++++++++++++ quotes/models.py | 3 +++ quotes/templates/quotes/author.html | 3 ++- quotes/templates/quotes/author_notes.html | 5 +++++ quotes/templates/quotes/onequote.html | 2 ++ 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 quotes/migrations/0002_author_notes.py create mode 100644 quotes/migrations/0003_auto_20160928_2223.py create mode 100644 quotes/templates/quotes/author_notes.html diff --git a/quotes/migrations/0002_author_notes.py b/quotes/migrations/0002_author_notes.py new file mode 100644 index 0000000..d7cc2f4 --- /dev/null +++ b/quotes/migrations/0002_author_notes.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quotes', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='notes', + field=models.TextField(blank=True), + ), + ] diff --git a/quotes/migrations/0003_auto_20160928_2223.py b/quotes/migrations/0003_auto_20160928_2223.py new file mode 100644 index 0000000..dc62f34 --- /dev/null +++ b/quotes/migrations/0003_auto_20160928_2223.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quotes', '0002_author_notes'), + ] + + operations = [ + migrations.AlterField( + model_name='author', + name='notes', + field=models.TextField(help_text=b'Notes for the author; may be left blank. Will not be HTML-escaped.', blank=True), + ), + ] diff --git a/quotes/models.py b/quotes/models.py index 9791aa0..53afcbe 100644 --- a/quotes/models.py +++ b/quotes/models.py @@ -4,6 +4,9 @@ from django.db import models class Author(models.Model): name = models.CharField(max_length=100) + notes = models.TextField(blank=True, help_text= \ + "Notes for the author; may be left blank. Will \ + not be HTML-escaped.") def __unicode__(self): return self.name diff --git a/quotes/templates/quotes/author.html b/quotes/templates/quotes/author.html index c3377ce..b09befc 100644 --- a/quotes/templates/quotes/author.html +++ b/quotes/templates/quotes/author.html @@ -4,9 +4,10 @@ {% block body %} -

{{ author.name }}

+{% include "quotes/author_notes.html" with author=author %} +

All the quotes for {{ author.name }}:

{% for quote in author.quote_set.all %} diff --git a/quotes/templates/quotes/author_notes.html b/quotes/templates/quotes/author_notes.html new file mode 100644 index 0000000..d666de6 --- /dev/null +++ b/quotes/templates/quotes/author_notes.html @@ -0,0 +1,5 @@ +{% if author.notes %} +

+

{{ author.notes|safe }}

+
+{% endif %} diff --git a/quotes/templates/quotes/onequote.html b/quotes/templates/quotes/onequote.html index 359cc7b..e814277 100644 --- a/quotes/templates/quotes/onequote.html +++ b/quotes/templates/quotes/onequote.html @@ -6,4 +6,6 @@ {% include "quotes/display.html" with quote=quote %} +{% include "quotes/author_notes.html" with author=quote.author %} + {% endblock %} -- 2.43.0