Posts

Showing posts from November, 2012

Using same template for add and edit using Django Model Form

If we want to use a customized form corresponding to a ModelForm, we have to do something like this <form action="" method="post"> <input name="{{form.field_a.html_name}}" type="text" /> <input type="submit" value="Submit" /> </form> This will work fine for adding data. But it's very common that we want to use this same form for updating data. In that case we have to populate the fields of the form with the existing data. We may want to do something like this <form action="" method="post"> <input name="{{form.field_a.html_name}}" type="text" value="{{form.field_a.value}}" /> <input type="submit" value="Submit" /> </form> But this may create some problem. If the field is optional and contains no data, in our generated html form, the value of that field will be "None". Surely, this is not

Useful Linux Commads

Delete files having specific extension recursively find /home -iname "*.mp3" -exec rm {} \;

Django With POSTGRESQL in Ubuntu

The first step is to change the database engine in the application’s settings.py file: 'ENGINE': 'django.db.backends.postgresql_psycopg2' Running  python manage.py syncdb  returned the following error: Error loading psycopg module: No module named psycopg I’ve tried installing the psycopg2 package, but that resulted in another error: You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application The libpq-dev package had to be installed to meet all the dependencies: sudo apt-get install libpq-dev sudo pip install psycopg2 But still, the syncdb command wasn’t returning the desired result: Peer authentication failed for user "someuser" I needed to open up the file /etc/postgresql/9.1/main/pg_hba.conf in a text editor (with root privileges) and change this line: local   all             all                                     peer to this: local   all             all