Posts tagged: Django

Creating a Custom Authentication Backend using Django

Today I have posted a new tutorial on djangorocks.com ‘Creating a Custom Authentication Backend‘.

The example created allows you to login to your Django application using your IMAP mail server to check your username & password.  Perfect if you are creating a webmail client or address book – and more I’m sure.

The tutorial is not as long as I would have hoped, but its rather difficult to add to when it really is quite a simple thing to implement.  Hope it helps.

PostgreSQL, how about you don’t make migration more complex

I am currently work on building a new site, from an existing one.  A lot of the front-end work is done, now to a lot of the admin.

Today a really quite annoying “feature” of PostgreSQL raises its head and takes up 3 hours of my time.  A lot of the data from the old site PHP/MySQL has been migrated to the new one Django/PostgreSQL which all worked fine, the front end works and its all lovely.  To maintain the old database id’s we inserted them all into the new database, this in itself is not the problem.  The problem arose what starting to adding new rows, which are expected to go to the end.

INSERT INTO table (title) VALUES ('my_title');

Instead of actually insert into a new row, this started working from id 1, throwing up errors whenever the id already existed and sometimes started to delete items from the end of the database.

Just what the hell.  After plenty of research and testing, initially expecting it to be a problem with my code and the problem is found.

Adding the Primary Key manually DOES NOT update the auto-increment value, and here is the fix (change field names where necessary)

SELECT SETVAL('sequence_name', (SELECT MAX(id) FROM table_name) + 1);

If you are using Django  you can generate the SQL by running, it does not run the automatically but you can pipe the response directly into the psql tool.

python manage.py sqlsequencereset appname

Very simple but this does not follow the MySQL style I am used to, then again SQLite also does things differently which had me stumped at first.

Django 1.2 and 1.1.2 released

Django 1.2 is now out, along with a bug-fix release for 1.1.  It looks like a bug has already been found, but that’s to be expected as the audience grows.  Better these problems are found early on.

Django 1.2 has a bunch of new features;

  • Support for multiple databases
  • Model validation
  • Improved CSRF protection
  • Messages framework
  • Object-level permissions
  • Permissions for anonymous users
  • Relaxed requirements for usernames
  • E-mail backends
  • “Smart” if tag
  • Template caching
  • Natural keys in fixtures
  • Fast failure for tests
  • BigIntegerField
  • Improved localization
  • readonly_fields in ModelAdmin
  • Customizable syntax highlighting
  • Syndication feeds as views
  • GeoDjango
  • JavaScript-assisted handling of inline related objects in the admin
  • New now template tag format specifier characters: c and u

Final, Estimated Django 1.2 release date

Over the last few weeks, Django contributors have been working hard finding and fixing bugs from 1.2 Beta 1.  The RC release has been set at around May 3, and final release May 10.  There are a couple of patches still to be completed, more here.

That being said, it also means that I am only a few weeks (hopefully) from completing one of my sites, mentioned in my last news post.  Although the site is not yet finished and there is still quote a lot to do, a lot of the code is in place, so I can start writing the tutorials.

A design is being completed and finalised by a friend of mine.  He doesn’t yet have his own site, but when he does and if I remember, I will add a link.  Things that will be used in this site;

This is the first site I have coded using the 960 grid system (although 2nd version) and this is also the first design Oli has done using it, if he gets some time, hopefully he will get me a quick post explaining some of the design process.

Also, Facebook connect code has been completed……for Django 1.1.  Although there should be no need to change much, there maybe some things I change, ie use of the new Messages framework.  This will be decided in the near future.

The Django & MooTools tutorials I promised.

No, they are not here yet, and I havn’t forgotten.  With Django 1.2 being out shortly I decided to redo parts of the site to reflect changes in the framework, some of which were mentioned in a previous post.  I would also like to review all of the new features, some changes and remove anything which will be Deprecated shortly.

I also stated the tutorials would cover MooTools.  Due to the fact I need to learn how to use jQuery in the fairly near future, I’ve decided I will use this for starting.  Granted the tutorials may not be the best, but will be far easier for beginners to understand, being one myself.  I will probably write the same things in MooTools over time as it is (at the moment) still my framework of choice.

Dansette