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
Install the comments framework by adding 'django.contrib.comments' to INSTALLED_APPS.
Run manage.py syncdb so that Django will create the comment tables.
Add the comment app's URLs to your project's urls.py
urlpatterns = patterns('',
...
(r'^comments/', include('django.contrib.comments.urls')),
...
)
And in your templates, load comment template tags
...
{% load comments %}
...
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
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
Open your terminal, extract and install sphinx
$tar -xvf sphinx-0.9.8.1.tar.gz
-
sphinx need mysql-dev install, if you use ubuntu linux install this
$sudo apt get install libmysqlclient15-dev
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 :
Django Project
If you want to learn Django, you have to visit Django home. http://djangoproject.com
Django Wiki
Django wiki, first place after you learn from djangoproject.
http://code.djangoproject.com/wiki/
B-list
Well, home of James Bennett. Top recommended.
http://www.b-list.org/
This week in Django
This week in django basically is a place where you can find update in django world.
http://thisweekindjango.com/
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