I am toying with a simple datamodel for a site I'm planning, and one of my app's models has a unique_together constraint.
If I try to add a duplicate record from the admin console, I get a traceback caused by an untrapped IntegrityError exception. unique_together appears to work as it should (the exception), but seeing a traceback in the console is sub-optimal. Am I doing something wrong (quite possibly, as I never got past the toying stage with Django)? Where is the right place to trap this exception and display a meaningful message in the admin "Add new object" page? Here is a copy of the traceback Traceback (most recent call last): File "/home/ludo/fashionstreets/django/core/handlers/base.py", line 64, in get_response response = callback(request, **param_dict) File "/home/ludo/fashionstreets/django/views/admin/main.py", line 780, in add_stage new_object = manipulator.save(new_data) File "/home/ludo/fashionstreets/django/utils/functional.py", line 3, in _curried return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "/home/ludo/fashionstreets/django/core/meta/__init__.py", line 1477, in manipulator_save new_object.save() File "/home/ludo/fashionstreets/django/utils/functional.py", line 3, in _curried return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "/home/ludo/fashionstreets/django/core/meta/__init__.py", line 807, in method_save ','.join(field_names), ','.join(placeholders)), db_values) File "/home/ludo/fashionstreets/django/core/db/base.py", line 10, in execute result = self.cursor.execute(sql, params) File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 95, in execute return self._execute(query, args) File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 114, in _execute self.errorhandler(self, exc, value) File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 33, in defaulterrorhandler raise errorclass, errorvalue IntegrityError: (1062, "Duplicate entry '1-1-5' for key 2")