Sat, 07 Dec 2013

Compatible with:

Here is my setup for a production Ubuntu server running Nginx as a web server and uWSGI to wrap my Django project and execute python code.

You need to place your project somewhere, usually I create an OS user for my project and create a virtual environment in there. For this example:


Sat, 07 Dec 2013

After a couple of years of messing around with Django, I have settled with this project structure that I find to be verbose enough to remind me where everything is:

.
├── apps
│   ├── blog
│   ├── core
├── fabfile
├── frontend
│   ├── apps
│   │   ├── blog
│   │   ├── core
│   │   └── pages
│   └── libs
│       ├── bootstrap
│       │   ├── css
│       │   ├── fonts
│       │   └── js
│       ├── jquery
│       │   └── js
│       ├── prettify
│       │   ├── css
│       │   └── js
│       └── redactor
├── project
│   ├── env
│   │   ├── local_env.py
│   │   └── prod.py
│   ├──...

Sat, 18 Aug 2012

For this website, I have a model called Category defined as follows:

class Category(models.Model):
    name = models.CharField(max_length=64)
    parent = models.ForeignKey('self', null=True, blank=True)

I wanted at some point to retrieve all the descendats of a certain category, unfortunately Django ORM doesn't have this feature out of the box (yet), so I had to create my own. The idea is create a recursive function that will collect a list of all the siblings at a certain depth and then move on to depth+1 until we get to the leaves.

def get_children(category):
    nodes = Category.objects.filter(par...