Django Tips #1:How to redirect comment post

Entry published on November 20th, 2008 and part of categories django and tag with tips

Django contrib comment is general comment app, so basically you can use it for any Django models. It is so easy to add comment feature to your app. Follow these steps and you'll have comment running on your website

  1. Install the comments framework by adding 'django.contrib.comments' to INSTALLED_APPS.

  2. Run manage.py syncdb so that Django will create the comment tables.

  3. Add the comment app's URLs to your project's urls.py

    urlpatterns = patterns('',
        ...
        (r'^comments/', include('django.contrib.comments.urls')),
        ...
    )
    
  4. And in your templates, load comment template tags

    ...
    {% load comments %}
    ...
    
  5. Just say you have post object, and want to add comment form, just put this code:

    ...
    <form action="{% comment_form_target %}" method="POST">
        {{ form }}
        <p class="submit">
        <input type="submit" name="submit" value="Submit">
        </p>
    </form>
    ...
    

Done. But, something bug me. I would rather to have user back to my post after giving comment. Note that django comment ...

Read "Django Tips #1:How to redirect comment post" and comments

Django Tutorial : Sphinxsearch and django-sphinx Part 2

Entry published on November 20th, 2008 and part of categories django and tag with django-sphinx , sphinx

Now, we are going to use sphinxsearch and integrate with our django models. For this tutorial, we will build library application, then we implement the book searching system using sphinxsearch.

Let's start, first we create django project.

$django-admin.py startproject sphinxlibrary
$cd sphinxlibrary

Now we create django app called 'library'.

$chmod +x manage.py
$./manage.py startapp library

We build simple model for our books.

from django.db import models

class Book(models.Model):
    
    title = models.CharField(max_length=255)
    isbn = models.CharField(max_length=10)
    summary = models.TextField()
    author = models.CharField(max_length=50)
    link = models.URLField(verify_exists=False)
    
    def __unicode__(self):
        return self.title

Before running manage.py syncdb, this is our settings.py for our tutorial. Make sure you have created database called 'sphinxlibrary' in your MySQL server.

import os
ROOT_PATH = os.path.dirname(__file__)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'sphinxlibrary'
DATABASE_USER = 'root'
DATABASE_PASSWORD = 'root'
DATABASE_HOST ...

Read "Django Tutorial : Sphinxsearch and django-sphinx Part 2" and comments

Django Tutorial : Sphinxsearch and django-sphinx Part 1

Entry published on November 14th, 2008 and part of categories django and tag with django-sphinx , sphinx

Long story short, you want to add search to your website. So you head to django documentation, after a while you realise that Django ORM didn't provide what you look for, that is full text search.

But, there is mysql full text search, see model search What's wrong with it? Nothing is wrong, just

  • It's only for MySQL
  • It didn't provide ranking search result
  • It lack of stemming

So, what is your recommendation then? Well, for this time I use sphinxsearch and django-sphinx.

Installing sphinxsearch

  1. Download sphinx at sphinxsearch.com, for this tutorial, I use Sphinx 0.9.8.1

    $wget http://sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
    
  2. Open your terminal, extract and install sphinx

    $tar -xvf sphinx-0.9.8.1.tar.gz
    
  3. sphinx need mysql-dev install, if you use ubuntu linux install this

    $sudo apt get install libmysqlclient15-dev
    
  4. Install sphinx to your ...

Read "Django Tutorial : Sphinxsearch and django-sphinx Part 1" and comments

Full text search solution for Django

Entry published on November 12th, 2008 and part of categories django and tag with search

Django is really rock, but hey, nobody is perfect, right?

Some people who use Django definitely know that there's no contrib.search, and just say you want full text search in your website then you have to implement it yourself. But before you dive into your cozy room, code all night long, it'd be better you look into these projects.

Wait! for those who don't know what full text search is, here quick explanation from wikipedia :

In text retrieval, full text search refers to a technique for searching a computer-stored document or database. In a full text search, the search engine examines all of the words in every stored document as it tries to match search words supplied by the user

So, here some solution full text search for Django :

MySQL full text search

MySQL full text search implementation in Django. Django documentation.

Sphinx and django-sphinx

Sphinx ...

Read "Full text search solution for Django" and comments

Top 5 Django Resources

Entry published on November 11th, 2008 and part of categories django

When learning something, you always come back to some places to get the knowledge, and here is my list :

  1. Django Project

    djangoproject.com

    If you want to learn Django, you have to visit Django home. http://djangoproject.com

  2. Django Wiki

    Django wiki

    Django wiki, first place after you learn from djangoproject. http://code.djangoproject.com/wiki/

  3. B-list

    b-list website

    Well, home of James Bennett. Top recommended. http://www.b-list.org/

  4. This week in Django

    This week in Django

    This week in django basically is a place where you can find update in django world. http://thisweekindjango.com/

  5. Django Snippet

    django snippet

    Django snippet is snippet repository of django user. Browse the snippet and you can get something new to learn. http://www.djangosnippets.org/

Read "Top 5 Django Resources" and comments

You can pick from these categories : django, howto, misc, project . Or you can browse patch-village archieve : Sep 2008 , Oct 2008 , Nov 2008

twitter bird "Miss my girl... tiwi." (gchandrasa)

Subscribe to patch-village