I am using HistorycalRecords
as table member
from simple_history.models import HistoricalRecords
class Delivery(BaseModel):
history = HistoricalRecords(
excluded_fields=['created_by', 'updated_by', 'updated_at'])
It create another table automatically named such as myapp_historicaldelivery
Now I want to use historical table itself as default model of view.
Because I would like to show the list of changed points.
class ActionLogListView(LoginRequiredMixin, ListSearchView):
template_name = "message_logs/action_log.html"
form_class = ActionLogSearchForm
model = Delivery.history // want to set here.
However it shows error, maybe because Delivery.history is not model.
TypeError: object of type 'NoneType' has no len()
HistorycalModel source code is here
https://github.com/jazzband/django-simple-history/blob/master/simple_history/models.py
How can I treat history as model class to show the list in view?
CodePudding user response:
Use Model.history.model
to access the history model for use in the generic views
class ActionLogListView(LoginRequiredMixin, ListSearchView):
template_name = "message_logs/action_log.html"
form_class = ActionLogSearchForm
model = Delivery.history.model