我有一个模型Managers
和一个代理模型MyManagers
。我试图在代理模型的管理面板中显示更改的字段,但Admin/history
仅显示用户、日期和操作。如何解决?
我的models.py
from django.db import models
from django.contrib import admin
from simple_history.models import HistoricalRecords
class Managers(models.Model):
name = models.CharField(max_length=30, default='')
lastname = models.CharField(max_length=30, default='')
enduser_id = models.CharField(max_length=8, default='', help_text=u"Please enter the end user id, like ABC1WZ1")
history = HistoricalRecords()
class Meta:
verbose_name = 'Manager'
verbose_name_plural = 'Managers'
def __str__(self):
return self.name + self.lastname
class ManagersAdmin(admin.ModelAdmin):
list_display= ('name','lastname','enduser_id')
class MyManagers(Managers):
class Meta:
proxy=True
def __str__(self):
return self.name.upper() +' '+self.lastname.upper()
class MyManagersAdmin(admin.ModelAdmin):
search_fields = ['name', 'lastname','enduser_id']
list_display = ('name', 'lastname','enduser_id')
history_list_display = ['name','lastname','enduser_id','changed_fields']
def changed_fields(self, obj):
if obj.prev_record:
var = obj.diff_against(obj.prev_record)
return var.changed_fields
return None
我的admin.py
:
from django.contrib import admin
from .models import *
# Additional board for assigning a manager to a Department.
admin.site.register(Managers, ManagersAdmin)
admin.site.register(MyManagers, MyManagersAdmin)