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?
Asked
Active
Viewed 4,008 times
6
-
This has been resolved by adding custom views to the admin. – user773328 Oct 19 '11 at 20:05
-
1Please post your solution as an answer and accept it if it's working. – Reto Aebersold Oct 20 '11 at 12:13
1 Answers
13
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)

dnozay
- 23,846
- 6
- 82
- 104