Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mongodbforms/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down