Login

Tag "unique_together"

Snippet List

Validation for 'unique' and 'unique_together' constraints (different version)

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.

  • newforms
  • forms
  • validation
  • unique_together
  • unique
  • constraints
Read More

Add validation for 'unique' and 'unique_together' constraints to newforms created dynamically via form_for_model or form_for_instance

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.

  • newforms
  • form_for_model
  • form_for_instance
  • unique_together
  • unique
  • formfield_factory
Read More

5 snippets posted so far.