Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
aeef4000
Commit
aeef4000
authored
1 year ago
by
Valentin Rigal
Browse files
Options
Downloads
Patches
Plain Diff
Add the condition to the serializer
parent
5ad81f36
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/training/serializers.py
+12
-1
12 additions, 1 deletion
arkindex/training/serializers.py
with
12 additions
and
1 deletion
arkindex/training/serializers.py
+
12
−
1
View file @
aeef4000
...
...
@@ -4,7 +4,7 @@ from collections import defaultdict
from
textwrap
import
dedent
from
django.db
import
transaction
from
django.db.models
import
Count
,
Q
from
django.db.models
import
Count
,
Exists
,
OuterRef
,
Q
from
drf_spectacular.utils
import
extend_schema_field
from
rest_framework
import
permissions
,
serializers
from
rest_framework.exceptions
import
PermissionDenied
,
ValidationError
...
...
@@ -575,6 +575,17 @@ class DatasetSerializer(serializers.ModelSerializer):
raise
ValidationError
(
"
Either do not specify set names to use the default values, or specify a non-empty list of names.
"
)
return
set_names
def
validate_unique_elements
(
self
,
unique
):
if
unique
is
True
and
self
.
instance
and
Exists
(
DatasetElement
.
objects
.
filter
(
set__dataset_id
=
OuterRef
(
self
.
instance
.
pk
))
.
values
(
"
element
"
)
.
annotate
(
dups
=
Count
(
"
element
"
))
.
filter
(
dups__gte
=
2
)
):
raise
ValidationError
(
"
Elements are currently contained by multiple sets.
"
)
return
unique
def
validate
(
self
,
data
):
data
=
super
().
validate
(
data
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment