This repository was archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.py
More file actions
52 lines (37 loc) · 1.34 KB
/
models.py
File metadata and controls
52 lines (37 loc) · 1.34 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
from django.db import models
from outer_join import WritableOuterJoin, OuterJoin
from outer_join.extra.models import AbstractDeleteRecord
from outer_join.extra.queryset import exclude_exact, filter_exact
class A0(models.Model):
key = models.IntegerField(unique=True)
field1 = models.IntegerField()
field2 = models.IntegerField()
class A1(AbstractDeleteRecord):
key = models.IntegerField(unique=True)
# IMPORTANT null=True should be set for all non-ON fields in a DeleteRecord
field1 = models.IntegerField(null=True)
field3 = models.IntegerField(null=True)
_save_check_fields = ('key',)
class A(models.Model):
key = models.IntegerField(unique=True)
field1 = models.IntegerField(null=True)
field2 = models.IntegerField(null=True)
field3 = models.IntegerField(null=True)
is_deleted = models.BooleanField(null=True)
class Meta:
managed = False
outer_join = WritableOuterJoin(
A1, A0,
on='key',
)
objects = outer_join.get_manager(
filter_initial_queryset=exclude_exact('is_deleted', True),
)()
readonly_outer_join = OuterJoin(
A1, A0,
on='key',
)
all_objects = readonly_outer_join.get_manager()()
deleted_objects = readonly_outer_join.get_manager(
filter_initial_queryset=filter_exact('is_deleted', True),
)()