|
22 | 22 | ) |
23 | 23 | from audit.related_object_type import RelatedObjectType |
24 | 24 | from core.models import ( |
| 25 | + SoftDeleteExportableManager, |
25 | 26 | SoftDeleteExportableModel, |
26 | 27 | abstract_base_auditable_model_factory, |
27 | 28 | ) |
@@ -300,6 +301,21 @@ def deep_clone(self, cloned_segment: Segment) -> "SegmentRule": |
300 | 301 | return cloned_rule |
301 | 302 |
|
302 | 303 |
|
| 304 | +class ConditionManager(SoftDeleteExportableManager): |
| 305 | + def get_queryset( |
| 306 | + self, |
| 307 | + ) -> models.QuerySet["Condition"]: |
| 308 | + # Effectively `Condition.Meta.ordering = ("id",) if ... else ()`, |
| 309 | + # but avoid the weirdness of a setting-dependant migration |
| 310 | + # and having to reload everything in tests |
| 311 | + qs: models.QuerySet["Condition"] |
| 312 | + if settings.SEGMENT_RULES_CONDITIONS_EXPLICIT_ORDERING_ENABLED: |
| 313 | + qs = super().get_queryset().order_by("id") |
| 314 | + else: |
| 315 | + qs = super().get_queryset() |
| 316 | + return qs |
| 317 | + |
| 318 | + |
303 | 319 | class Condition( |
304 | 320 | SoftDeleteExportableModel, |
305 | 321 | abstract_base_auditable_model_factory(["uuid"]), # type: ignore[misc] |
@@ -343,6 +359,8 @@ class Condition( |
343 | 359 | created_at = models.DateTimeField(null=True, auto_now_add=True) |
344 | 360 | updated_at = models.DateTimeField(null=True, auto_now=True) |
345 | 361 |
|
| 362 | + objects: typing.ClassVar[ConditionManager] = ConditionManager() |
| 363 | + |
346 | 364 | def __str__(self): # type: ignore[no-untyped-def] |
347 | 365 | return "Condition for %s: %s %s %s" % ( |
348 | 366 | str(self.rule), |
|
0 commit comments