djangodjango-viewsdjango-simple-history

How to parse the queryset from django-simple-history?


How to parse the queryset from the django-simple-history to a html table with columns: history_id, history_date and etc. I'm inherit DetailView class


Solution

  • Example form django-simple-history:

    from django.db import models
    from simple_history.models import HistoricalRecords
    
    class Poll(models.Model):
        question = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')
        history = HistoricalRecords()
    
    class Choice(models.Model):
        poll = models.ForeignKey(Poll)
        choice_text = models.CharField(max_length=200)
        votes = models.IntegerField(default=0)
        history = HistoricalRecords()
    

    now you can access history by:

    all_history = poll.history.all()
    

    more info :

    1. https://django-simple-history.readthedocs.io/en/latest/querying_history.html
    2. https://django-simple-history.readthedocs.io/en/latest/quick_start.html