-
Notifications
You must be signed in to change notification settings - Fork 515
Expand file tree
/
Copy pathmanagers.py
More file actions
58 lines (53 loc) · 2.15 KB
/
managers.py
File metadata and controls
58 lines (53 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from django.db.models import Prefetch
from softdelete.models import SoftDeleteManager
from features.models import FeatureSegment, FeatureState
from features.multivariate.models import MultivariateFeatureStateValue
class EnvironmentManager(SoftDeleteManager):
def filter_for_document_builder(
self,
*args,
extra_select_related: list[str] | None = None,
extra_prefetch_related: list[Prefetch | str] | None = None,
**kwargs,
):
return (
super()
.select_related(
"project",
"project__organisation",
*extra_select_related or (),
)
.prefetch_related(
"project__segments",
"project__segments__rules",
"project__segments__rules__rules",
"project__segments__rules__conditions",
"project__segments__rules__rules__conditions",
"project__segments__rules__rules__rules",
Prefetch(
"project__segments__feature_segments",
queryset=FeatureSegment.objects.select_related("segment"),
),
Prefetch(
"project__segments__feature_segments__feature_states",
queryset=FeatureState.objects.select_related(
"feature",
"feature_state_value",
"environment",
"environment_feature_version",
),
),
Prefetch(
"project__segments__feature_segments__feature_states__multivariate_feature_state_values",
queryset=MultivariateFeatureStateValue.objects.select_related(
"multivariate_feature_option"
),
),
*extra_prefetch_related or (),
)
.filter(*args, **kwargs)
)
def get_queryset(self):
return super().get_queryset().select_related("project", "project__organisation")
def get_by_natural_key(self, api_key):
return self.get(api_key=api_key)