This repository has been 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
/
Copy pathmodels.py
59 lines (40 loc) · 1.43 KB
/
models.py
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
59
from django.db import models
from outer_join import WritableOuterJoin, OuterJoinInterceptor
from outer_join.extra.models import AbstractDeleteRecord
from outer_join.extra.queryset import exclude_exact
class B0(models.Model):
key = models.IntegerField(unique=True)
val = models.IntegerField()
class B1(AbstractDeleteRecord):
_save_check_fields = ('key',)
key = models.IntegerField(unique=True)
val = models.IntegerField(null=True)
class B(models.Model):
key = models.IntegerField(primary_key=True)
val = models.IntegerField(null=True)
is_deleted = models.BooleanField(null=True)
class Meta:
managed = False
base_manager_name = 'base_objects'
outer_join = WritableOuterJoin(
B1, B0,
on='key',
)
objects = outer_join.get_manager(
filter_initial_queryset=exclude_exact('is_deleted', True),
)()
base_objects = outer_join.get_manager()()
class A(models.Model):
key = models.IntegerField(unique=True)
b = models.ForeignKey(
B, related_name='a_set', on_delete=models.SET_NULL,
# IMPORTANT: cannot have db_constraint since it's not referencing a real table
db_constraint=False,
null=True,
)
models.ManyToManyField(B, db_constraint=False)
val = models.IntegerField()
class Meta:
base_manager_name = 'objects'
interceptor = OuterJoinInterceptor()
objects = interceptor.get_manager()()