I would like to add admin view capability to django simple-history. I created a history attribute on a model and this model now appears in the admin docs section automatically without any further code from me, but it does not appear in the admin section. I want users to be able to see the history of changes and to apply an undo function using the most_recent function. Do you have any suggestions for how to approach this?
if your models are:
from simple_history.models import HistoricalRecords
from django.db import models
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 = models.CharField(max_length=200)
votes = models.IntegerField()
history = HistoricalRecords()
then you can have an admin that looks like:
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import Poll, Choice
admin.site.register(Poll, SimpleHistoryAdmin)
admin.site.register(Choice, SimpleHistoryAdmin)
or you can customize it ...
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import Poll
class PollAdmin(SimpleHistoryAdmin):
list_display = ('question', 'pub_date')
admin.site.register(Poll, PollAdmin)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With