Tag | python

  1. Django: Count Aggregates with Conditions

    In Django, One-to-Many relations are modeled by the ForeignKey. Under some circumstances, we may wish to collect some information (e.g. count, min, max, avg, etc) from related objects. For example, in a blog app, we may wish to build a table which lists the title and the number of …


  2. Full-text Search with Django and PostgreSQL

    Django has several PostgreSQL database functions to support full-text search. If you are using PostgreSQL as the database backend, then it is easy to add full-text search to your Django app.

    In this post, I would like to build an demo app with full-text search. This post covers several PostgreSQL-specific …


  3. Django ORM and Updating Counters

    Counters are common in website development. Most websites collect the number of page views with counters. E-commerce websites keep track of the quantity of a commodity with counters. However, it is hard to implement a correct counter with Django ORM.

    In this post, I would like to cover three ways …


  4. Python Property Decorator

    Recently, I was tracing the source code of PyPy, and a special decorator named @property caught my attention. It seems to be a mechanism for Python programmers to create a getter, a setter, and a deleter for an instance variable. For example, how could we intercept the access to a …


  5. Flask and Socket.IO

    Under some scenarios, we would like to push a message from an HTTP server to clients. For example, in a group messaging application, whenever a user sends a message to the server, the server has to push such message to everyone. Since 2001, several techniques have been proposed. Eventually, WebSocket …


  6. Python New Style Class

    Recently, I am curious about this code snippet:

    class Test(object):
        def __init__():

    Why do we have to extend or inherit from object type?

    There are no differences with or without (object) in Python 3. But there are significant differences in Python 2. If a class inherits (either directly …


  7. Comparison and Sorting in Python3

    Although I have written Python for several years, I am still not very familiar with its idioms. In particular, I don't quite understand how to compare and sort the objects in Python. That's the reason why I am writing this article.

    The rest of this article consists of following sections …


  8. Waliki Installation

    Waliki is a simple wiki app for Django. We can write wiki contents with reStructuredText and the contents will be stored in a Git repository. In this post, I would like to introduce the instructions to install Waliki.

    Getting Started

    First, install the related Ubuntu packages:

    $ sudo apt-get install git …