File tree Expand file tree Collapse file tree 6 files changed +5
-37
lines changed
Expand file tree Collapse file tree 6 files changed +5
-37
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,6 @@ Unreleased
2525 lists are sorted by the related object. This should help prevent flaky tests. (gh-1128)
2626- ``diff_against() `` has a new keyword argument, ``foreign_keys_are_objs ``;
2727 see usage in the docs under "History Diffing" (gh-1128)
28- - Added ``HistoricalQuerySet.select_related_history_tracked_objs() ``; see usage in the
29- docs under "Prefetching Related Objects of Historical Records" (gh-1128)
3028
31293.5.0 (2024-02-19)
3230------------------
Original file line number Diff line number Diff line change @@ -53,8 +53,8 @@ the model modifications.
5353 the value of the deleted object's primary key.
5454
5555 Note that this will add extra database queries for each related field that's been
56- changed - as long as the related objects have not been prefetched (using e.g.
57- ` select_related_history_tracked_objs() < Prefetching Related Objects >`_ ).
56+ changed - as long as the related objects have not been prefetched
57+ (using e.g. `` select_related() `` ).
5858
5959 A couple examples showing the difference:
6060
Original file line number Diff line number Diff line change @@ -225,33 +225,3 @@ You can also prefetch the objects with this relationship using something like th
225225
226226 Poll.objects.filter(something).prefetch_related(Prefetch(' history' , queryset = Poll.history.order_by(' -history_date' ),
227227 to_attr = ' ordered_histories' )
228-
229-
230- .. _`Prefetching Related Objects` :
231-
232- Prefetching Related Objects of Historical Records
233- ------------------------------------------------ -
234-
235- If you find yourself wanting to access the related objects of some historical records,
236- but without inducing additional database queries,
237- `` HistoricalQuerySet`` has a method called `` select_related_history_tracked_objs()``
238- that you can use.
239- This is a convenience method that calls `select_related()` _ with all the names of
240- the model' s history-tracked ``ForeignKey`` fields.
241- For example:
242-
243- .. code- block:: python
244-
245- class Membership(models.Model):
246- person = models.ForeignKey(Person, on_delete = models.CASCADE )
247- group = models.ForeignKey(Group, on_delete = models.CASCADE )
248-
249- history = HistoricalRecords(excluded_fields = [" person" ])
250-
251-
252- # This will prefetch `group` (not `person`, since it's excluded)
253- Membership.history.select_related_history_tracked_objs()
254-
255- Prefetching historical many- to- many relations is currently not supported.
256-
257- .. _select_related(): https:// docs.djangoproject.com/ en/ stable/ ref/ models/ querysets/ # select-related
Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ def get_history_queryset(
129129 # Only select_related when history_user is a ForeignKey (not a property)
130130 qs = qs .select_related ("history_user" )
131131 # Prefetch related objects to reduce the number of DB queries when diffing
132- qs = qs .select_related_history_tracked_objs ()
132+ qs = qs ._select_related_history_tracked_objs ()
133133 return qs
134134
135135 def get_history_list_display (self , request ) -> Sequence [str ]:
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ def latest_of_each(self):
9191 )
9292 return latest_historics
9393
94- def select_related_history_tracked_objs (self ):
94+ def _select_related_history_tracked_objs (self ):
9595 """
9696 A convenience method that calls ``select_related()`` with all the names of
9797 the model's history-tracked ``ForeignKey`` fields.
Original file line number Diff line number Diff line change @@ -399,7 +399,7 @@ def access_related_objs(records):
399399
400400 # With prefetching:
401401 with self .assertNumQueries (1 ):
402- historical_records = Choice .history .select_related_history_tracked_objs ()
402+ historical_records = Choice .history ._select_related_history_tracked_objs ()
403403 self .assertEqual (len (historical_records ), num_choices )
404404 with self .assertNumQueries (0 ):
405405 access_related_objs (historical_records )
You can’t perform that action at this time.
0 commit comments