From db34ed2d2566b355ee4f37265e5f7e04d4ceb746 Mon Sep 17 00:00:00 2001 From: Rafael Novello Date: Wed, 12 Jun 2013 23:41:46 -0300 Subject: [PATCH] Changed to support unique_with --- mongodbforms/documents.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mongodbforms/documents.py b/mongodbforms/documents.py index d26f2651..227b5c12 100644 --- a/mongodbforms/documents.py +++ b/mongodbforms/documents.py @@ -387,7 +387,7 @@ def _post_clean(self): def validate_unique(self): """ Validates unique constrains on the document. - unique_with is not checked at the moment. + unique_with is supported now. """ errors = [] exclude = self._get_validation_exclusions() @@ -396,6 +396,9 @@ def validate_unique(self): filter_kwargs = { f.name: getattr(self.instance, f.name) } + if f.unique_with: + for u_with in f.unique_with: + filter_kwargs[u_with] = getattr(self.instance, u_with) qs = self.instance.__class__.objects().filter(**filter_kwargs) # Exclude the current object from the query if we are editing an # instance (as opposed to creating a new one)