Coder’s Eye

A site about one of the three passions in my life.

Coder’s Eye header image 2

A Django Killer App - Web Table Data

September 12th, 2006 · 2 Comments

Light BulbYet another great use for Django is to make trivial the creation of shared tables & forms for internal projects. It is one of the most common needs in any size company, “Make me a web form to capture these data.” “Oh, and make sure to keep it locked down so that xxx dept can’t see it, and only you and I can modify it.”

Making these kind of web apps is one of the most boring tasks possible, yet they are both common and almost always poorly implemented. After all, they are just for internal use, right? And “they” rarely give you enough time to make a decent app anyway.

Well Django to the rescue. In four steps, you can have an app with far more functionality and usability than you’d ever have with some quick-hack up PHP page or ASP.

Step 1: Create the project directory and app directory

$ django_admin startproject projectbase
$ cd projectbase
$ ./manage.py startapp projectname

Step 2: Edit projectbase/settings.py

You can leave most everything default, at the simplest you can simply use a SQLite database, which requires no password or database setup. Be sure to enable the admin app, like so:


DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/path/to/your/project.db'
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'projectbase.projectname'
)

Step 3: edit projectbase/projectname. Models.py: Here you put the class or classes you want to track in your table. Here is an example taken from a simple migration tracking app I made at work.


from django.db import models

class Migration(models.Model):
    account = models.CharField(maxlength=30)
    email = models.EmailField(blank=True, null=True)
    prop = models.CharField(maxlength=30, null=True)
    requestor = models.EmailField()
    domains = models.TextField()
    target = models.CharField(maxlength=6)
    status = models.CharField(maxlength=20,
                              blank=True, null=True)
    created = models.DateField(null=True, blank=True)
    scheduled = models.DateField(null=True, blank=True)
    completed = models.DateField(null=True, blank=True)
    archived = models.DateField(null=True, blank=True)
    notes = models.TextField(null=True, blank=True)

    def __repr__(self):
        return self.account

    __str__ = __repr__

    class Meta:
        get_latest_by = "created"
        ordering = ("created",)

    class Admin:
        list_display = ("account", "email", "prop",
                        "requestor", "domains",
                        "target", "status", "notes",
                        "created", "scheduled",
                        "completed", "archived")
        search_fields = ("account", "domains")

Step 4: Create the database and tables

$ manage.py syncdb

At this point, you have a full fledged system available to you. Start Django however you please, add a few users and show off. You’ll have a full app available, with sorting of tables, updating, searching, and full authentication. All in a half hour of work.

Technorati Tags: , ,

Tags: OS · Tips · Django

Bookmark this article

del.icio.us:A Django Killer App - Web Table Data digg:A Django Killer App - Web Table Data spurl:A Django Killer App - Web Table Data wists:A Django Killer App - Web Table Data simpy:A Django Killer App - Web Table Data newsvine:A Django Killer App - Web Table Data blinklist:A Django Killer App - Web Table Data furl:A Django Killer App - Web Table Data reddit:A Django Killer App - Web Table Data fark:A Django Killer App - Web Table Data blogmarks:A Django Killer App - Web Table Data Y!:A Django Killer App - Web Table Data smarking:A Django Killer App - Web Table Data magnolia:A Django Killer App - Web Table Data segnalo:A Django Killer App - Web Table Data gifttagging:A Django Killer App - Web Table Data

2 responses so far ↓

  • 1 Alex V. Koval // Oct 6, 2006 at 8:25 pm

    I am switching to Django, and love automated interface and the way it goes. In fact, for my own admin applications inside of Zope, I wrote a “table” which have cross-related but a little different set of functions (http://dev.zwarehouse.org/browser/projects/HTMLTableZWAK/trunk)

    This HTMLTable works with any SQL, but not with Django ORM, so may be I will either rewirte it or try to extend Django admin to that direction.

    Exactly what I am missing now in automated admin:
    1. Ability to specify own ‘actions’ to apply to set of results (selected on page, or to complete all results). This usually means deletion of a set, import, export, and some very custom actions like (ex: subscribe/unsubscribe etc which are custom for application)
    2. Ability to change fields listed by admin for a session (columns on screen)
    3. Ability to have ‘function’ fields where field is a result of some external function work for a field. This allows doing (slow) sub-queries or special data formatting.

    Sooner or later, such kind of object will allow to build a full-functional
    admin interfaces. As for now, admin only allows very basic editing of object related data, you can not build a complete admin application on that.

  • 2 naisioxerloro // Nov 28, 2007 at 1:52 pm

    Hi.
    Good design, who make it?

Leave a Comment