Handling unique_together errors in Django forms

April 26, 2012

Reading time ~1 minute

I ran into a problem with Django’s unique_together feature earlier. The thing is that unique_together validates on the database level and thus the errors does not seem to be propagated to the forms validation properly.

For me that resulted in a form that was completed with no errors communicated to the user, but the data was not saved to database.

Here’s a solution for the problem, where I clean the data my self and throw an error if needed.

You can then handle the form in the view just as usual with like below.

Running vim-airline with Maximum Awesome

I use [Maximum Awesome](https://github.com/square/maximum-awesome) when I code in [vim](http://www.vim.org/), it's a great starting place...… Continue reading

Quicksort implementation in Python

Published on August 04, 2014

Fibonacci generator in Python

Published on August 04, 2014