bittersweet.models module

bittersweet.models.validated_get_or_create(klass, **kwargs)[source]

Similar to get_or_create() but uses the methodical get/save including a full_clean() call to avoid problems with models which have validation requirements which are not completely enforced by the underlying database.

For example, with a django-model-translation we always want to go through the setattr route rather than inserting into the database so translated fields will be mapped according to the active language. This avoids normally impossible situations such as creating a record where title is defined but title_en is not.