Skip to content

Commit

Permalink
Allow filtering annotation fields by ids of annotation values
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorjerse committed Oct 19, 2023
1 parent ac09d83 commit 10c6fb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Changed
descriptor
- Add ``annotations`` property to the ``Entity`` object in Python processes
- Allow filtering ``AnnotationField`` by ids
- Allow filtering ``AnnotationField`` by ids of ``AnnotationValue`` instances


===================
Expand Down
1 change: 1 addition & 0 deletions resolwe/flow/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ class Meta(BaseResolweFilter.Meta):
fields = {
**{
"id": NUMBER_LOOKUPS[:],
"values__id": NUMBER_LOOKUPS[:],
"name": TEXT_LOOKUPS[:],
"label": TEXT_LOOKUPS[:],
"type": TEXT_LOOKUPS[:],
Expand Down
11 changes: 11 additions & 0 deletions resolwe/flow/tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,17 @@ def test_annotation_field(self):
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["name"], self.annotation_field1.name)

# Filter by annotation values id.
request = factory.get(
"/",
{"values__id__in": [self.annotation_value1.pk], "fields": "name"},
format="json",
)
response = self.annotationfield_viewset(request)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["name"], self.annotation_field1.name)

# Filter by required.
request = factory.get("/", {"required": False}, format="json")
response = self.annotationfield_viewset(request)
Expand Down

0 comments on commit 10c6fb3

Please sign in to comment.