File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,8 @@ def _as_of_set(self, date):
87
87
queryset = self .filter (history_date__lte = date )
88
88
for original_pk in set (
89
89
queryset .order_by ().values_list (pk_attr , flat = True )):
90
- last_change = queryset .filter (
91
- ** {pk_attr : original_pk }).latest ('history_date' )
92
- if last_change .history_type != '-' :
93
- yield last_change .instance
90
+ changes = queryset .filter (** {pk_attr : original_pk })
91
+ last_change = changes .latest ('history_date' )
92
+ if changes .filter (history_date = last_change .history_date , history_type = '-' ).exists ():
93
+ continue
94
+ yield last_change .instance
Original file line number Diff line number Diff line change @@ -66,3 +66,16 @@ def test_modified(self):
66
66
as_of_list = list (
67
67
self .model .history .as_of (self .now - timedelta (days = 1 )))
68
68
self .assertEqual (as_of_list [0 ].changed_by , self .obj .changed_by )
69
+
70
+
71
+ class AsOfAdditionalTestCase (TestCase ):
72
+
73
+ def test_create_and_delete (self ):
74
+ now = datetime .now ()
75
+ document = models .Document .objects .create ()
76
+ document .delete ()
77
+ for doc_change in models .Document .history .all ():
78
+ doc_change .history_date = now
79
+ doc_change .save ()
80
+ docs_as_of_tmw = models .Document .history .as_of (now + timedelta (days = 1 ))
81
+ self .assertFalse (list (docs_as_of_tmw ))
You can’t perform that action at this time.
0 commit comments