File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -673,7 +673,7 @@ def get_queryset(self, **hints) -> QuerySet:
673673 None ,
674674 )
675675 if history and histmgr :
676- return histmgr .as_of (history . _as_of )
676+ return histmgr .as_of (getattr ( history , " _as_of" , history . history_date ) )
677677 return super ().get_queryset (** hints )
678678
679679
@@ -708,7 +708,7 @@ def get_queryset(self):
708708 None ,
709709 )
710710 if history and histmgr :
711- queryset = histmgr .as_of (history . _as_of )
711+ queryset = histmgr .as_of (getattr ( history , " _as_of" , history . history_date ) )
712712 else :
713713 queryset = super ().get_queryset ()
714714 return self ._apply_rel_filters (queryset )
Original file line number Diff line number Diff line change @@ -2012,3 +2012,14 @@ def test_historic_to_historic(self):
20122012 to_historic (ot1 ), TestOrganizationWithHistory .history .model
20132013 )
20142014 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 ("history_date" )[0 ]
2024+ pt1i = pt1h .instance
2025+ self .assertEqual (pt1i .organization .name , "original" )
You can’t perform that action at this time.
0 commit comments