unique_together with many to many fields
To use it, append all your model save methods with a IntegrityError catcher.
- unique_together
- m2m-manytomanyfield
- many-to-many-field
To use it, append all your model save methods with a IntegrityError catcher.
unique_together doesn't work with ManyToMany, yet. See: http://code.djangoproject.com/ticket/702 Here a simple test in save() that would raise a IntegrityError.
signal handler for checking unique_together manually. Also available via django-tools: http://code.google.com/p/django-tools/
This is a slightly different and extendend version of this snippet: http://www.djangosnippets.org/snippets/260/ Unique constraints for single fields are validated in a clean_FIELD, instead of globally in the form's clean() method, so that the error messages are correctly assigned to each field. Additionally, you can specify mappings for unique_together constraints to assign those error messages to a specific field as well (instead of having them in non_field_errors(), where they would normally be.
This snippet provides a form_for_model and form_for_instance function which create newforms that respect the unique and unique_together constraints defined in the model. One thing about the coding style in this code snippet: Classes are capitalized even if they're passed as arguments. Thus "Model" is a model class while "model" is a model instance.
5 snippets posted so far.