This is an exceedingly simple FAQ application for Django, which I wrote for Henry.
Do what you want with it, & let me know of any bugs etc.
The Model
To store the FAQs!
PYTHON:
-
from django.db import models
-
from django.conf import settings
-
-
# Create your models here.
-
class Faq( models.Model ):
-
"""Stores FAQS"""
-
question = models.CharField(maxlength=255) # The Q
-
answer = models.TextField() # the A
-
post_date = models.DateTimeField(auto_now_add=True, db_index=True) # when we answered it
-
-
def __str__( self ):
-
return self.question
-
-
class Admin:
-
search_fields = ( 'question', 'answer' )
-
date_hierarchy = 'post_date'
-
list_display = ( 'question', 'post_date' )
-
fields = ((None, { 'fields': ( 'question', 'answer' )}),)
The View:
To get the FAQs...
PYTHON:
-
from django.shortcuts import render_to_response
-
from django.template import RequestContext
-
-
# Change "myproject" to your project name
-
from myproject.about.models import *
-
-
def about(request):
-
"""Displays all the FAQs"""
-
faqs = Faq.objects.all()
-
return render_to_response( 'about.html', { 'faqs':faqs, },
-
context_instance=RequestContext(request) )
The Template:
...and finally, the template to bring it all together:
HTML:
-
{% extends "base.html" %}
-
{% load markup %}
-
-
{% block content %}
-
<h2>Frequently Asked Questions:</h2>
-
{% comment %}
-
build a "table of contents first..."
-
{% endcomment %}
-
<ul> {% for faq in faqs %}
-
{% endfor %}</ul>
-
{% comment %}
-
now show the FAQs
-
{% endcomment %}
-
-
{% for faq in faqs %}
-
<a title="{{ faq.id }}" name="{{ faq.id }}"></a>
-
<h3 class="q"> {{ faq.question|escape }}</h3>
-
<p class="faq"> {{ faq.answer|textile }}</p>
-
{% endfor %}
-
-
{% endblock %}
The End:
You couldn't get any simpler than that without using a textfile..
Note: this requires textile - but you can easily change the filter in the template to whatever you want. You will need to have django.contrib.markup installed though.
Download the Django FAQ Application
--Simon