我在 django 的 simple_history 中使用 diff_against。請參閱 simple_history 檔案中的“history diffing”:
https://django-simple-history.readthedocs.io/en/latest/history_diffing.html
我有這一切作業,但它指出:
"diff_against also accepts 2 arguments excluded_fields and included_fields to either explicitly include or exclude fields from being diffed."
我不知道如何傳遞這些欄位。這是我正在作業的內容(沒有任何包含或排除欄位):
def historical_changes(qry, id):
changes = []
if qry is not None and id:
last = qry.first()
for all_changes in range(qry.count()):
new_record, old_record = last, last.prev_record
if old_record is not None:
delta = new_record.diff_against(old_record)
changes.append(delta)
last = old_record
return changes
我使用以下方法在詳細視圖中呼叫它:
changes = historical_changes(hpn.history.all(), hpn.pk)
這一切都有效。然后我嘗試包含“exclude_field”。這些是我嘗試過的,但沒有奏效:
delta = new_record.diff_against(old_record, excluded_fields('geom'))
or
delta = new_record.diff_against(old_record).excluded_fields('geom')
or
delta = new_record.diff_against(old_record.excluded_fields('geom'))
這是很簡單的事情,但我沒有弄清楚。任何幫助都會很棒。謝謝。
uj5u.com熱心網友回復:
你應該像這樣使用它:
delta = new_record.diff_against(old_record, excluded_fields=['geom'])
diff_against接受關鍵字引數excluded_fields而不是類excluded_fields的方法HistoricalRecords。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/343431.html
標籤:Python 姜戈 django-简单的历史
下一篇:了解相關欄位提供查詢集的要求
