Tuesday, October 6, 2009

My New MacBook Pro


So I finally bought a new Mac a month ago. I seriously thought of getting one when they came out with Intel processors but got stuck waiting for the price to drop to more reasonable level. Didn't happen :( of course, so when my creaky 6 yrs old Linux desktop at home finally drop dead of old age, took the plunge and got a new 13-inch MacBook Pro

So here's my thoughts on my shinny new Mac laptop. I've divided it into 3 parts. The fanboy rave, raving rants and savvy apps.

Fanboy Rave and Why You Should Get Mac
  • Hardware: Macs are stylish and well-crafted piece computer machinery. Like most Apple products, it's meant to look gorgeous. Aesthetics has always been one of their strong suits and in Mac it's visceral! And of course, it work flawlessly!
  • User Interface: Simplicity. At the end day, there's something to be said about a well-designed and consistent User Interface. I know Linux desktop and it is nowhere near as elegant or as polished as Mac.
  • Performance: Generally faster, more responsive and smoother experience when using Mac. Of course, a lot of it has to do with it's tightly coupled hardware and software stack. And dual-core processor with 4 GB memory is no slouch. Windows on comparable hardware spec is still a crash waiting to happen. (Note: Linux scream on just about any hardware, in case you're wondering).
  • Applications: Safari's webarchive feature, Preview and iLife. In Linux, I used either Evince or Okular, two very capable apps. After using Preview, these two nice apps just doesn't cut it anymore. Firefox's equivalent of webarchive feature doesn't even compare. As for iLife, it's the next best thing after invention of the Internet (or so I've been told, I have yet to try it).
  • Core: Beneath the simplicity and elegant facade of Mac OSX beats the heart of true Unix beast. I'm Linux man. 'nuff said.

Raving Rants and Some Caveats
  • A new Mac is absolutely, horrendously expensive. Even now, every time I pass an Apple store, I kept thinking who can afford these stuff (except for all those rabid fanboys). I was scouring the whole of Metro Manila looking for a store with a least markup. Found one at BHS, but even in store with scaled back pricing, Mac is still outrageously over-price that I had to wipe a tear in my eye when I had to hand my credit card at the counter.
  • There is no single repository for Mac software. If you have a specific Mac software in mind, you generally track them down through Google.
  • Installing software in Mac is awkward. It is so late 80's, it's weird. In Mac, there are two ways to install software and they're both counter-intuitive, clunky and messy. If you want to see software installation/management done right then check out Linux yum or apt-get. It is light-years ahead of Mac. It just works.
  • While most task are incredibly easy to do in Mac, some are just plain exasperating.
Try burning an ISO image in Mac. In Linux, you simply right-click the file and choose 'Burn' and that's it. The appropriate app is open, and work unobtrusively in the background and when done, eject the CD/DVD. No fuss, no muss. How so in Mac? You go to your Finder and start Disk Utility program. From the File menu, choose Open Disk Image and select ISO to burn. Pick the right volume, then click 'Burn' button. Hardly intuitive, even for a long time Mac users.
  • Minor pet peeve: In Linux and Windows, applications are categorize into different groups. This makes it less confusing for people. For instance, all Internet-related programs are group under Programs/Internet menu. This makes it more natural and intuitive. In Mac, it's all bunch together in the Application folder so you have to muddle through all the available apps, it's silly. You can drag and drop apps to the Dock or Desktop, if don't mind a cluttered a workspace.

Of Savvy Apps and Savvy Users
  • QuickSilver (QS): Of all Mac app, QS is by far kick ass the most! And this is app only available in Mac. I've been using it for a while and it is truly a must-have. It's basically an app launcher with search capability but things you could do with this baby, awesomeness! If you've been nursing carpal tunnel, do your self a favor and try QS. Be warned though, QS goes against the whole Mac philosophy of "dumb-down" approach and adhere more closely to time-honored Unix/Linux tradition of using keyboard (rather than your mouse) to work with your computer. QS is what vim is to Unix/Linux. Steep learning curve but well worth the effort in increase productivity.
  • Firefox: The day Safari have the following add-ons, is the day I ditched Firefox.
* Gmail Notifier, check new emails w/o logging in manually.
* AdBlock Plus, for those pesky Internet ads and pop-ups.
* Delicious Bookmark add-on
* Seamless integration with Tor for bypassing block sites at work.
* Vimperator. If you haven't used vi/vim before, this plugin is probably not for you. It is so un-Mac, it's ridiculously awesome!
  • Transmission: Unless you've been living under a rock for last couple of years, then you've probably have seen, used and abused the charms of bittorrent. Transmission is lightweight and ΓΌber-fast client for the bittorrent universe. Wat!?!? You haven't heard of bittorrent? Think of it as iTunes store but with wider selection, and all gratis!
  • VirtualBox: It's a virtualization software which is basically a way for you to run 'guest' operating system on top of your Mac and it acts like any other apps inside your Mac. If you're familiar with Parallel or VMware, it's the same except that it's open-source so no need to pay extra (actually, apps I've mentioned here are all open-source). Handy, if you need to test networking stuff or do cross-platform development or install apps that only run on Windows.
  • VLC: Over 90% of all movies and torrent videos you'll download are in avi format. For reason unknown, Quicktime choose not to support it. Use it for all the movies/videos that QuickTime doesn't play nice with.
  • Fink: In you're coming in from Linux/Unix background, then you'll surely love this little app that could. If you used a lot open-source tools that hasn't been prettified for Mac, you should get this. Fink is basically a wrapper to install/run open-source apps.
If you have no idea how flexible or how powerful open-source tools are compared to their Mac brethren, check this: My nephew CJ love playing with PhotoBooth with his PowerRanger moves. So if I want to collate all his pics into a single, animated picture, I would simply type the following command from the Terminal console:
    convert pictures*.jpg animated.gif
And there you go. The command might seem archaic, but here's the result:

CJ

iLife can of course, do the same thing, and so if working on command line is not your cup of tea, you can always revert back to it.

Of Conclusion and Trophy Girlfriends
So how do I like my new Mac? Linux (for those not in the know) is like having a smart, intelligent girlfriend. Nice! Mac is like having a trophy gf. Rock on!

Coolness, my gentle anonymous dear readers, is to basked in the reflected glory and pure awesomeness of having a Mac. Supersonic!

Friday, July 31, 2009

Creating playable DVDs using DeVeDe

Heh, I just blog how to rip movies from your DVD a few months ago and now I'm blogging how to turn video clips (ie. avi, mpeg, wmv) into a DVD that you could just pop in to your DVD player. Double heh heh! :-)

I've been getting a number of 'request' from friends and relatives to burn their video clips from their camera into something viewable in their DVD player. Also, my sis has been bugging me about it. She has this collection of mpeg files she took from a recital from one of her in-law's daughter and she wants to show it during a family get-together.

So a quick google for an open-source DVD authoring tool turn out the DeVeDe program that can get the job done. Better yet, it's already in the RPM Fusion repo, so installing it and getting it to run is dead easy. Kudos to the developer, it's great tool.

Anyways, someone might find this info useful, who knows... So I'm blogging this one for posterity.

-----

Step 1: Log in as root and run the following command (I'm running Fedora 11 and Internet connection is required):

# yum -y install devede

Note: All in all, it was only around 6MB file download since I'm already using most of it's dependencies (ie. mplayer, mencoder, etc).

Step 2: From the command line, run the following:

$ rpm -q devede
$ devede

The first window you should get is the following:


Click on the Video DVD and you should get the following menu:


Step 3: From here, simply click the Properties button under Titles and change the title. Note that each Title is film on it's own. And each Titles is composed of Files.

Step 4: Add the Files that will be under the Title. Simply click Files->Add and in the next dialog box, find the file you would like to add.

Step 5: (Optional) Add another Title. Note that when you insert the DVD to the DVD Player, these Titles are the different categories of your film.




Step 6: Choose the appropriate Default Format, PAL or NTSC. Now this is probably the only tricky part when trying to create a playable DVDs. I didn't have a clue what were these format were, so I stuck with default one (ie. PAL) only to find out later on that our DVD player is NTSC... oh well... you learn.

Step 7: Click Forward button. It should then prompt you to "Choose the folder where DeVeDe will create the DVD image and a name for it". Just stick the default setting, should be alright.

Step 8: Click the Advance Option below, and then choose Video Options->Scaling Mode->Add Black Bars. This option will make sure that your video is scaled appropriately (it will add black line above and below your video). And then click the OK button

Step 8: It should now start converting all your files into a single iso image.


Step 9: Make yourself a tea or go for a run or something. Depending on how fast your computer is, this might take a while. On my creaky old 2.40GHz Celeron box, it took an hour and half to encode 2.4GB of mpeg data into an iso image. It's excruciatingly slow.


Step 10: After your Devede tool is done, it will create a file with an *.iso extension in a directory you specified during the initial steps. Now all you have to do is burn this iso image into any blank DVDs. Probably the easiest way to burn it is to use K3B or Brasero utilities. Or just burn it directly using the following command:

$ growisofs -dvd-compat -Z /dev/dvd=/path/to/file/movie.iso

Voila! Success!

Saturday, April 25, 2009

Building RPM packages for Fedora

Here's a quickie tutorial on how to build rpm packages for Fedora. I was going to checkout Tribler and build an rpm package for it but installing Tribler on F10 box was such royal pain in the ass that I've given up on it, well at least until Fedora 11 hits the ftp sites next month.

Tribler is your friendly next-generation bleeding-edge p2p tool. And it sounds awesome too based from the web site description. Unfortunately, it's too bleeding-edge for me :-( I wanted to check out an alternative to bittorrent since the TPB trial didn't go well for the operators of the site (they've just been handed a guilty verdict) but it looks like I have to wait it out until most of these next-generation bittorrent tools mature.

In any case Tribler is such a pain because one of the package it requires is python-apsw (*sigh* they had choose this package when there are other more established and well-supported interface to SQLite and nope it's not package as Python eggs either which would have been too easy for the developers).

So ok, I don't mind building it manually, but python-apsw requires sqlite-3.6.12 version. F10 only shipped sqlite-3.5.9, you can upgrade it of course, but sqlite is used by a number of packages, so upgrading it might have some unforseen consequences down the road.

Anyways, I digress. Since I've already put up the time and effort in learning how to build rpm packages, I might as well build something that I can blog about (my cheatsheet for future projects).

First off, best practice for building rpm state that you do it as regular user _not_ as root. We'll package the nano text editor since it's small and nifty utility. Also, I'm assuming that you have Internet connection.

Step1:

Download nano-2.0.9.tar.gz package (the latest as of this writing) from:

http://www.nano-editor.org/download.php


Step2:

Install the development tools required to build the rpm packages (here you need to be root unless you've setup a sudo account).

# yum -y groupinstall "Development Tools"
# yum -y install rpmdevltools
# yum -y install rpm-build

Also, make sure to uninstall the nano package.

# yum -y remove nano

Step3:

Setup the rpm work tree

$ cd ~/
$ rpmdev-setuptree rpmbuild

Note: The rpmdev-setuptree will create the ~/.rpmmacros file and the rpmbuild directory. And inside the rpmbuild directory, you should see the following subdirectories:
  • BUILD is where the actual build process takes place.
  • RPMS is where you can find the rpm package file if your build is successul.
  • SOURCES is where you put the nano source you've downloaded.
  • SPECS is where you create the nano.spec file
  • SRPMS is where you can find the source rpm package if your build is successful.
Step4:

Move the nano source file to the ~/rpmbuild/SOURCES directory.

In your ~/.rpmmacros file, add the following settings:

%packager Your_Name_Here plus email address
%vendor Your_Fictitious_Vendor_Here

Step5:

Create the nano.spec file below. Now this is the tricky part since this is where most of the magic happens when creating rpm packages. A lot of the settings here are pretty cryptic.

$ cd ~/rpmbuild/SPEC
$ rpmdev-newspec nano

The rpmdev-newspec will create the nano.spec file which will serve as your template spec file, fill in the blanks and you're set.

For clarity of steps, I've put the content of nano.spec file further below.

Step6:

Create the rpm package using the following steps:

Build the package, this is the "%build" stage in the nano.spec file.

$rpmbuild -bc nano.spec

If you got a clean build, the last line in the output is "+ exit 0", run the "%install" part of nano.spec file.

$rpmbuild -bi nano.spec

If everything build cleanly, you can then create the source and rpm file.

$rpmbuild -ba nano.spec

Actually, if you're pretty sure that your spec file is written correctly, you can proceed directly to "rpmbuild -ba nano.spec". I used "-bc" and "-bi" switch to catch any errors/problems in my spec file.

You should now have source rpm package in your ~/rpmbuild/SRPMS and the binary rpm package at ~/rpmbuild/RPMS/i386 directory.

Success!!

Step7:

Install the nano rpm package (if you haven't done so, remove the default nano package installed on your system, and run this command as root):

$ su -
# yum remove nano
# cd /home/
# yum localinstall ~/rpmbuild/RPMS/i386/nano-2.0.9-1.fc10.i386.rpm --nogpgcheck
# rpm -qi nano

Sweet!

Note: since we didn't signed our rpm package, we need to use --nogpgcheck.

Here's the content of nano.spec file. Ignore the line number, I use it as reference in describing the settings:
  1. Name: nano
  2. Version: 2.0.9
  3. Release: 1%{?dist}
  4. Summary: GNU nano is a small text editor in Linux
  5. Group: Applications/Editors
  6. License: GPLv2+
  7. URL: http://wwww.nano-editor.org/
  8. Source0: nano-2.0.9.tar.gz
  9. BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release})

  10. BuildRequires: ncurses-devel, autoconf, gettext-devel, groff
  11. Requires(post): /sbin/install-info
  12. Requires(preun): /sbin/install-info

  13. %description
  14. GNU nano is a small and friendly text editor.

  15. %prep
  16. %setup -q

  17. %build
  18. %configure --enable-all
  19. make

  20. %install
  21. rm -rf %{buildroot}
  22. make DESTDIR="%{buildroot}" install
  23. rm -f %{buildroot}%{_infodir}/dir

  24. %find_lang %{name}

  25. %post
  26. /sbin/install-info %{_infodir}/%{name}.info.gz %{_infodir}/dir
  27. exit 0

  28. %clean
  29. make clean
  30. rm -rf %{buildroot}

  31. %files -f %{name}.lang
  32. %defattr(-,root,root,-)
  33. %doc AUTHORS BUGS COPYING ChangeLog INSTALL NEWS README THANKS TODO
  34. %{_bindir}/*
  35. %{_mandir}/man*/*
  36. %lang(fr) %{_mandir}/fr/man*/*
  37. %{_infodir}/nano.info*
  38. %{_datadir}/nano

  39. %changelog
  40. * Fri May 8 2009 Fedora Release
  41. - First build of nano
Line1 and line2/4/5/6 are self-exlanatory.
Line3: refers to release number of the package. The %{?dist} is macro that translate into nano-2.0.9-1.<fc10>i386. So basically %{?dist} is translated in to the name and version of your distro.
Line5: The list of valid groups can be found at /usr/share/doc/rpm-4.6.0/GROUPS
Line8: refers to where you can find the source file for nano. This is the ~/rpmbuild/SOURCES directory
Line9: This is the directory where 'build' happens. This directory is created on the fly in /var/tmp.
Line11: Dependencies you need to compile your source file.
Line12: Scriptlet to run after you install nano. Basically, this is the utility you use when you install an Info file from the source into your system.
Line13: Scriptlet to run before it uninstall itself.
Line18/19: Basically untar the nano source file into the BUILD directory. The -q option means to stay quiet (do not show output to the screen).
Line21-23: set the configuration and then run 'make' (compile the software).
Line25-28: This where 'packaging' of rpm happens.
Line30: refers to the /usr/share/locale directory where nano.mo files will be installed
Line32: Scriptlet to install the info and man pages to the appropriate directory.
Line36-38: Remove all the directory created during the 'build' process. In this case, the %{buildroot} refers to the directories created in ~/rpmbuild/BUILDROOT.
Line40: These are the binary files, documentation, config, etc that you want your rpm package to install on your system.
Line41: Default attributes/permission of files. The first '-' refers to file permission, the first 'root' refers to owner of the file, second 'root' refers to group owner, and second '-' refers to directory permission.
Line43-47: Directory where your binaries/man pages will be installed.
Line49-51: This is the log file that shows up when you run "rpm -q --changelog nano"

As usual, there are heaps of tutorials on how to build rpm packages. You can find the most definitive guide here. But I've mostly used Fedora-specific tutorials found here, here, and here.

Wednesday, April 15, 2009

Nifty USB Drive Tool

Hey, found this nifty tool that you can use when your usb stick starts acting up. Yesterday, when I tried using my usb stick to move my avi files, I keep getting these "read-only filesystem" messages, even when I manually and forcibly mount the usb stick in rw mode. Did a cursory check on the /var/log/messages, turns out that vfat filesystem used by usb stick have been clobbered (plugging the usb in and out have finally taken it's toll)

Anyways, quickie solution would be to run the fsck.vfat utility.

# fsck.vfat <usb>

Where <usb> is the usb device file name (depending on your fdisk -l output). What fsck.vfat does is repair FAT32 filesystem used in your usb sticks.

Wednesday, January 7, 2009

Django Setup


Been learning a new web framework since I had time on my hand last month. I thought I'd get started on web development since this seems to be where the action is headed in the near future (mobile apps look good too but couldn't afford those toys so I'm sticking with something more 'freebie').

Two of the most popular web framework in the scene are Ruby on Rails and Django. RoR is out, since I'm not keen to learn a new language just so I could try the latest/greatest web frameworks. Fortunately, Django was built on top of Python, so it was really more of applying my rudimentary python skill into another domain.

Looking for Django tutorial/howtos, I found the online version of "The Definitive Guide to Django" here which is probably the best intro for Django. 'been playing around with it and I thought I'd create own quickie reference material that I can quickly jump into without reading the voluminous manual.

Part 1: Introduction

Django is a web framework, basically what it does is do most of the grunt work of web development and provide you with plenty of abstraction (or shortcuts) to most common and frequently done task when developing web apps. For instance, you can use Django's authentication module for authenticating your web users rather than cobbling something amateurish on your own.

Django follows the MVC (Model-View-Controller) philosophy which implement a strict separation of different parts of the application (aka loose coupling) which makes it easy to change parts of the code without impacting other parts of the application. However, in Django they call it MTV (Model-Template-View). Model is your database setup while Template is generally your presentation layer (ie. html/ajax) of your web app and View is your "business logic layer" and binds your model and template.

Part 2: Installation and Setup of Django

Step 1: I use Fedora, open your terminal, go to root and run the following:
yum -y install Django mysql MySQL-python
rpm -q Django mysql MySQL-python

Step 2: Start a Django projet
mkdir ~/djcode #This is where your Django code will live
cd ~/djcode
django-admin.py startproject mysite #Create the appropriate config files
cd mysite
python manage.py runserver& #Run the development web server
firefox http://127.0.0.1:8000 #Test your Django setup

You should now have working Django setup and ready for your web development

Part 3: Simple Django Web Application

Let's create a simple web page to illustrate how Template and View (in MTV acronym) works.

Step 1:
Create a template directory where you'll place all your html files.
mkdir Templates

Step 2:
You need to tell Django where to find your templates. In your ~/djcode/mysite/settings.py find the TEMPLATE_DIRS settings and add the following:
TEMPLATE_DIRS = (
'/home/gene/djcode/mysite/Templates',
)

Step 3:
Go into the Template directory (ie. "cd Templates") and create a file named basic.html:

The "{{ nickname }}" and the "{{ date }}" inside the html file indicate that these are variables that will be defined when you 'render' this template.

Step 4:
We now need to create a view. Remember that view describe which data you see and not how you see your data. View process that data before it is presented. So in the ~/djcode/mysite directory, create the view.py file:

from django.shortcuts import render_to_response
import datetime

def current_datetime(request):
name = 'Gene Ordanza'
now = datetime.datetime.now()
return render_to_response('basic.html', {
'date': now,
'nickname': name })

If you're fairly new to web framework and not coming in from programming background, render_to_response is the tricky part. Both 'nickname' and 'date' in the basic.html are variable and so is the 'name' and 'now' in the view.py. What view.py does is call the template (in this case basic.html) through render_to_response method and then defined the variable inside. Remember: separation of different part of your web app is what you're after. So your web designer or web developer are free to mess around with their respective area of expertise without messing other parts of your application.

Step 5:
You now have to map your template to your view. Now this is where your URLconf comes in. URLconf file is something like table of contents for your web app. Basically, you go to URL address then your Django framework will map that URL to a view you've define. In turn, your view will call your template. That in essence is how your Django works in the background.

In the ~/djcode/mysite/urls.py file, add the following:
from mysite.view import current_datetime

urlpatterns = patterns(' ',
(r'^time/$', current_datetime)
)

Also, in ~/djcode/mysite/settings.py file, look for the TIME_ZONE variable and change it to whatever appropriate time zone for you. In my case, that's TIME_ZONE = 'Asia/Manila'. Voila! That's it, point your browser to the following address http://127.0.0.1:8000/time.



Part 4: Configure Database

One of the core feature of Django is ORM (Object-Relational Mapper) and this is where most web frameworks really shines. Basically, ORM enables you to link your data models in Django to the actual database (in this case MySQL). Loosely defined, our data models refer to your database tables. With Django's model, you don't have to get down and dirty with database access. Most of the data retrieval and manipulation can be done within Django as it provide a nice abstraction to your database application. For our web app, we'll create a book/author/publisher database.

Step 1:
Setup your MySQL server
service mysqld start
mysqladmin password #setup your password
mysqladmin -u root -p create testdb #create the testdb database in MySQL

Step 2:
In your ~/djcode/mysite/settings.py file, add the following:
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'testdb'
DATABASE_USER = 'root
DATABASE_PASSWORD = 'hello' #Or whatever password you've set

Step 3:
You now need to create an app where you model and views will reside for that application.
cd ~/djcode/mysite
python manage.py startapp books

Step 4:
The command above should create a subdirectory called ~/djcode/mysite/books. Inside that directory, edit the file models.py and add the following:
from django.db import models

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=30)
city = models.CharField(max_length=50)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=30)
website = models.URLField()

def __unicode__(self):
return self.name

class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField()

def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)

class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()

def __unicode__(self):
return self.title

Step 5:
At this point, the testdb database is still empty. We've defined 3 models (Publisher, Author, Books) that correspond to your database tables (that we haven't created yet). We need to activate these models to create the actual tables. In the settings.py file, find the INSTALLED_APPS setttings and comment out the five default apps enabled there (ie. 'django.contrib.admin') by prepending a '#' before the app name. And then add the 'mysite.books' app in the INSTALLED_APPS, so it should look like this:
INSTALLED_APPS = (
# 'django.contrib.auth',
# 'django.contrib.contenttype',
# 'django.contrib.sessions',
# 'django.contrib.sites',
# 'django.contrib.auth',
'mysite.books',
)

In the MIDDLEWARE_CLASSES comment out the middleware apps as well.

Step 6:
The 'mysite.books' is the web app that we're working on. We now need to validate/check our settings, just to be sure that we don't have any typo or illegal settings. In the ~/djcode/mysite directory, run the following command:
python manage.py validate

If no error came up, then you can now commit the Django model to the MySQL database,
python manage.py syncdb

When you run the command above, it should prompt you to also create a root account and password.

That's it! You have now created and sync the following tables: books_publisher, books_author, books_book.

Part 5: Set-up of Admin Site

Like the ORB feature, the Admin Site is one of the core feature of Django and what makes developing web apps for Django easier and more productive. With Admin Site, writing boilerplate code for your web app infrastructure is taken care for you so you can immediately add, change and view content for your web site and avoid getting bogged down with the usual repetitive code of making production-ready interface for your web site.

Step 1:
In the settings.py file, uncomment back the settings for INSTALLED_APPS and the MIDDLEWARE_CLASSES to enable the Admin Site.

Step 2:
Sync your database. The settings that were uncommented above are packages that need to sync to the database. In your ~/djcode/mysite directory, run the following:
python manage.py syncdb

This will prompt you to create a root account for your Admin site.

Step 3:
In urls.py, uncomment the following code for the Django admin:
from django.contrib import admin
admin.authodiscover()

urlpatterns = patterns(' ',
# . . .
(r'^admin/', include(admin.site.urls)),
# . . .
)

Step 4:
Point your browser to the http://127.0.0.1:8000/admin and you should get the following web page:



Step 5:
Try to log in using the root account you've created when you run the "python manage.py syncdb" and you should get the following web pages:



Try to create another account, change their attributes, play around and get comfortable with the Admin Site feature.

Step 6:
We'll now hook our models to the Admin Site by creating the admin.py file in the ~/djcode/mysites/books directory (ie. the books/ directory was created in Part 4). In our admin.py, add the following:
from django.contrib import admin
from mysite.books.models import Publisher, Author, Book

admin.site.register(Publisher)
admin.site.register(Author)
admin.site.register(Book)

Restart your runserver to let the development web server read the file. Go back to your Admin site and log in and you should now see the following:



At this point, you can now add or change data for your Publisher, Author, and Book database. Now, how difficult was that?

Part 6: Creating Forms

To extend our simple Publisher/Author/Book database, we'll create a rudimentary search capability that let users search books by title.

Step 1:
We'll need to create an HTML front-end for the search form. In the Template directory, create a simple html search form.

Step 2:
Create the search view that will call our html search form. In your ~/djcode/mysite/books/view.py file, add the following:
from django.shortcuts import render_to_response

def search_form(request):
return render_to_response('search_form.html')

Step 3:
In your urls.py file, map the html searh_form to the Django view.
from mysite.books import view

urlpatterns = patterns(' ',
# . . .
(r'^search-form/$', views.search_form),
# . . .
)

Step 4:
If you try to check the url http://127.0.0.1:8000/search-form, you'll get an error since we haven't yet coded the /search/ view yet. So in your view.py, add the following:
from django.http import HttpResponse
from django.shortcuts import render_to_response
from mysite.books.models import Book

def search(request):
if 'q' in request.GET and request.GET['q']:
q = request.GET['q']
books = Book.objects.filter(title__icontains=q)
return render_to_response('search_results.html', {'books':books, 'query':q})
else:
return HttpResponse('Please submit a search term.')

Step 5:
We now need to pass the books object to another template called 'search_results.html' that will display our search results. In your Template directory, create the search_results.html:

Step 6:
Now visit http://127.0.0.1:8000/search-form/ and search for both existing and non-existing titles in your database. And that's it!





If you've read this far, then you really ought to read the more concise, better written, in it's original form found here :-) If you have questions though, feel free to submit a comment and I'll try to help out.