File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -673,7 +673,7 @@ def get_queryset(self, **hints) -> QuerySet:
673
673
None ,
674
674
)
675
675
if history and histmgr :
676
- return histmgr .as_of (history . _as_of )
676
+ return histmgr .as_of (getattr ( history , " _as_of" , history . history_date ) )
677
677
return super ().get_queryset (** hints )
678
678
679
679
@@ -708,7 +708,9 @@ def get_queryset(self):
708
708
None ,
709
709
)
710
710
if history and histmgr :
711
- queryset = histmgr .as_of (history ._as_of )
711
+ queryset = histmgr .as_of (
712
+ getattr (history , "_as_of" , history .history_date )
713
+ )
712
714
else :
713
715
queryset = super ().get_queryset ()
714
716
return self ._apply_rel_filters (queryset )
Original file line number Diff line number Diff line change @@ -2012,3 +2012,16 @@ def test_historic_to_historic(self):
2012
2012
to_historic (ot1 ), TestOrganizationWithHistory .history .model
2013
2013
)
2014
2014
self .assertIsNone (to_historic (org ))
2015
+
2016
+ # test querying directly from the history table and converting
2017
+ # to an instance, it should chase the foreign key properly
2018
+ # in this case if _as_of is not present we use the history_date
2019
+ # https://github.com/jazzband/django-simple-history/issues/983
2020
+ pt1h = TestHistoricParticipanToHistoricOrganization .history .all ()[0 ]
2021
+ pt1i = pt1h .instance
2022
+ self .assertEqual (pt1i .organization .name , "modified" )
2023
+ pt1h = TestHistoricParticipanToHistoricOrganization .history .all ().order_by (
2024
+ "history_date"
2025
+ )[0 ]
2026
+ pt1i = pt1h .instance
2027
+ self .assertEqual (pt1i .organization .name , "original" )
You can’t perform that action at this time.
0 commit comments