2

Hello I have some problems to add django-reversion and django-reversion-compare modules.

I created new project and I want to track user_auth log changes with django-reversion (after register User model with django-reversion i wanna use django-reversion-compare).

from django.contrib import admin
from django.contrib.auth.models import User
from reversion.admin import VersionAdmin


@admin.register(User)
class UserModelAdmin(VersionAdmin):
pass

when I want to register model User I got error

django.contrib.admin.sites.AlreadyRegistered: The model User is already registered

How I can use django-reversion and django-reversion-compare with User model?

4

1 回答 1

7

The auth.User model is already registered in the django admin that's why you see the error. To avoid it you have two options:

A. Unregister the User admin and then register it again as a VersionAdmin: Something like this:

from django.contrib import admin
from django.contrib.auth.models import User
from reversion.admin import VersionAdmin

admin.site.unregister(User) 
admin.site.register(User, VersionAdmin) 

B. Use the registration API of django-reversion (https://django-reversion.readthedocs.io/en/stable/api.html#registration-api) to register the model without modifying your admin, for example:

import reversion
from django.contrib.auth.models import User

reversion.register(User)
于 2017-09-12T21:41:27.263 回答