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:
  1. from django.db import models
  2. from django.conf import settings
  3.  
  4. # Create your models here.
  5. class Faq( models.Model ):
  6. """Stores FAQS"""
  7. question = models.CharField(maxlength=255) # The Q
  8. answer = models.TextField() # the A
  9. post_date = models.DateTimeField(auto_now_add=True, db_index=True) # when we answered it
  10.  
  11. def __str__( self ):
  12. return self.question
  13.  
  14. class Admin:
  15. search_fields = ( 'question', 'answer' )
  16. date_hierarchy = 'post_date'
  17. list_display = ( 'question', 'post_date' )
  18. fields = ((None, { 'fields': ( 'question', 'answer' )}),)

The View:

To get the FAQs...

PYTHON:
  1. from django.shortcuts import render_to_response
  2. from django.template import RequestContext
  3.  
  4. # Change "myproject" to your project name
  5. from myproject.about.models import *
  6.  
  7. def about(request):
  8. """Displays all the FAQs"""
  9. faqs = Faq.objects.all()
  10. return render_to_response( 'about.html', {  'faqs':faqs, },
  11. context_instance=RequestContext(request) )

The Template:

...and finally, the template to bring it all together:

HTML:
  1. {% extends "base.html" %}
  2. {% load markup %}
  3.  
  4. {% block content %}
  5. <h2>Frequently Asked Questions:</h2>
  6. {% comment %}
  7. build a "table of contents first..."
  8. {% endcomment %}
  9. <ul>         {% for faq in faqs %}
  10.     <li><a href="http://simon.net.nz/wp-admin/#%7B%7B%20faq.id%20%7D%7D">{{ faq.question|escape }}</a></li>
  11. {% endfor %}</ul>
  12. {% comment %}
  13. now show the FAQs
  14. {% endcomment %}
  15.  
  16. {% for faq in faqs %}
  17. <a title="{{ faq.id }}" name="{{ faq.id }}"></a>
  18. <h3 class="q"> {{ faq.question|escape }}</h3>
  19. <p class="faq"> {{ faq.answer|textile }}</p>
  20.     {% endfor %}
  21.  
  22. {% 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