Skip to content

Commit d3ad544

Browse files
authored
Merge pull request #49 from namespace-ee/documentation-and-prefetch-ordering
Django 5 support
2 parents 079832e + d3e72ad commit d3ad544

File tree

11 files changed

+634
-457
lines changed

11 files changed

+634
-457
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ python:
88
- "3.9"
99
- "3.10"
1010
- "3.11"
11+
- "3.12"
1112

1213
matrix:
1314
fast_finish: true
1415
include:
15-
- python: 3.11
16+
- python: 3.12
1617
env: TOXENV=lint
1718

1819
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors

HISTORY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 2.2.0 (2024-10-22)
4+
- Support for Django 5
5+
- Django supported versions `5.0 -> 5.1`
6+
- Python supported versions `3.10 -> 3.12`
7+
- Django-rest-framework supported versions. `3.15`
8+
- Add support for request dependant prefetch filtering
9+
- refactored code for better readability
10+
- prefetches from view are also used when determining sideloading prefetches
11+
- Add support for drf_spectacular documentation
12+
- Add prefetch related support for multi source fields
13+
314
## 2.1.0 (2024-01-26)
415

516
- Support for Django 4

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ DRF-sideloading is an extension to provide side-loading functionality of related
127127
Include **SideloadableRelationsMixin** mixin in ViewSet and define **sideloading_serializer_class** as shown in example below.
128128
Everything else stays just like a regular ViewSet.
129129
Since version 2.0.0 there are 3 new methods that allow to overwrite the serializer used based on the request version for example
130+
Since version 2.1.0 an additional method was added that allow to add request dependent filters to sideloaded relations
130131
131132
```python
132133
from drf_sideloading.mixins import SideloadableRelationsMixin
@@ -144,11 +145,11 @@ DRF-sideloading is an extension to provide side-loading functionality of related
144145
# Add prefetches for the viewset as normal
145146
return super().get_queryset().prefetch_related("created_by")
146147
147-
def get_sideloading_serializer_class(self):
148+
def get_sideloading_serializer_class(self, request=None):
148149
# use a different sideloadable serializer for older version
149150
if self.request.version < "1.0.0":
150151
return OldProductSideloadableSerializer
151-
return super().get_sideloading_serializer_class()
152+
return super().get_sideloading_serializer_class(request=request)
152153
153154
def get_sideloading_serializer(self, *args, **kwargs):
154155
# if modifications are required to the serializer initialization this method can be used.
@@ -157,6 +158,14 @@ DRF-sideloading is an extension to provide side-loading functionality of related
157158
def get_sideloading_serializer_context(self):
158159
# Extra context provided to the serializer class.
159160
return {"request": self.request, "format": self.format_kwarg, "view": self}
161+
162+
def add_sideloading_prefetch_filter(self, source, queryset, request):
163+
#
164+
if source == "model1__relation1":
165+
return queryset.filter(is_active=True), True
166+
if hasattr(queryset, "readable"):
167+
return queryset.readable(user=request.user), True
168+
return queryset, False
160169
```
161170
162171
6. Enjoy your API with sideloading support

0 commit comments

Comments
 (0)