from django.contrib import admin
# Register your models here.
+from .models import Author, Quote, Tag
+admin.site.register(Author)
+admin.site.register(Tag)
+admin.site.register(Quote)
from django.db import models
# Create your models here.
+
+class Author(models.Model):
+ name = models.CharField(max_length=100)
+
+ def __unicode__(self):
+ return self.name
+
+class Tag(models.Model):
+ tag = models.CharField(max_length=100)
+
+ def __unicode__(self):
+ return self.tag
+
+ class Meta:
+ ordering = ("tag", )
+
+class Quote(models.Model):
+ text = models.TextField()
+ author = models.ForeignKey(Author)
+ tags = models.ManyToManyField(Tag, blank=True)
+
+ def __unicode__(self):
+ return self.author.name + ": " + self.text
+
--- /dev/null
+a {
+ color: black;
+}
+
+.quote {
+ background-color: #ffbd33;
+ border: 3px solid #ff5733;
+ padding: 1.5em 2em;
+ margin: 2em 30em;
+}
+
+.quote .author {
+ padding-left: 5em;
+}
+
+.quote .author .name {
+ font-style: italic;
+}
--- /dev/null
+{% extends 'quotations/base.html' %}
+
+{% block body %}
+
+
+<h1>{{ author.name }}</h1>
+
+<p>All the quotes for {{ author.name }}:<p>
+
+{% for quote in author.quote_set.all %}
+ {% include "quotations/display.html" with quote=quote %}
+{% endfor %}
+
+
+{% endblock %}
--- /dev/null
+<html>
+ <head>
+ {% load staticfiles %}
+ <link rel="stylesheet" type="text/css" href="{% static 'quotations/style.css' %}" />
+ </head>
+ <body>
+ {% block body %}
+ {% endblock %}
+ </body>
+</html>
--- /dev/null
+<div class="quote">
+ <p class="text">
+ {{ quote.text }}
+ </p>
+
+ <p class="author">
+ — <span class="name"><a href="{% url 'author' quote.author.id %}">
+ {{ quote.author.name }}
+ </a></span>
+ </p>
+
+ {% if quote.tags.all %}
+ <p class="tags">
+ Tags:
+ {% for tag in quote.tags.all %}
+ <a href="{% url 'tags' tag.id %}">{{ tag.tag }}</a>
+ {% endfor %}
+ </p>
+ {% endif %}
+</div>
--- /dev/null
+{% extends 'quotations/base.html' %}
+
+{% block body %}
+
+{% for quote in quotes %}
+ {% include "quotations/display.html" with quote=quote %}
+{% endfor %}
+
+{% endblock %}
--- /dev/null
+{% extends 'quotations/base.html' %}
+
+{% block body %}
+
+{% include "quotations/display.html" with quote=quote %}
+
+{% endblock %}
--- /dev/null
+{% extends 'quotations/base.html' %}
+
+{% block body %}
+
+
+<h1>{{ tag.tag }}</h1>
+
+<p>All the quotes tagged with {{ tag.tag }}:<p>
+
+{% for quote in tag.quote_set.all %}
+ {% include "quotations/display.html" with quote=quote %}
+{% endfor %}
+
+
+{% endblock %}
--- /dev/null
+from django.conf.urls import url
+
+from . import views
+
+urlpatterns = [
+ url(r'^$', views.random, name='random'),
+ url(r'^show/(?P<quote_id>[0-9]+)/$', views.onequote, name="onequote"),
+ url(r'^tag/(?P<tag_id>[0-9]+)/$', views.tags, name="tags"),
+ url(r'^author/(?P<author_id>[0-9]+)/$', views.author, name="author"),
+ url(r'^all/$', views.all, name="all"),
+]
from django.shortcuts import render
+from django.http import HttpResponse
+from django.template import loader
+
+from random import randint
+
+from .models import Author, Quote, Tag
# Create your views here.
+def onequote(request, quote_id):
+ q = Quote.objects.get(id=quote_id)
+ context = { 'quote' : q }
+ return render(request, 'quotations/onequote.html', context)
+
+def random(request):
+ count = Quote.objects.count()
+ return onequote(request, randint(1, count))
+
+def tags(request, tag_id):
+ tag = Tag.objects.get(id=tag_id)
+ context = { 'tag' : tag }
+ return render(request, 'quotations/tag.html', context)
+
+def author(request, author_id):
+ author = Author.objects.get(id=author_id)
+ context = { 'author' : author }
+ return render(request, 'quotations/author.html', context)
+
+def all(request):
+ quotes = Quote.objects.all()
+ context = { 'quotes' : quotes }
+ return render(request, 'quotations/all.html', context)