Shahrukh Mohammad
Shahrukh Mohammad

Reputation: 1105

How should I add django import export on the User Model

I am trying to enable django import export on the django user model. I have tried defining a model admin class, unregistering the user model and then registering the new user admin class. But it doesn't work.

my admin.py looks like this -

from django.contrib.auth.admin import UserAdmin as BaseAdmin
from import_export.admin import ImportExportModelAdmin
from import_export import resources

class UserResource(resources.ModelResource):
    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'email')

class UserAdmin(BaseAdmin, ImportExportModelAdmin):
    resource_class = UserResource

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

I want to know how can I achieve this? Is there some other way I can apply django import export on the user model?

Upvotes: 0

Views: 1244

Answers (1)

Leonardo
Leonardo

Reputation: 1

Your code is working. You just need to import the User model:

from django.contrib.auth.models import User

Upvotes: 0

Related Questions