user2330497
user2330497

Reputation: 419

How can i have two ModelAdmin of the same model in Django Admin

I have the Model Admin like this registered on admin site

site.register(Student, ModelAdmin)

Now i have one more admin which is inherited from Model Admin with some custom data like this

class StudentAdmin(ModelAdmin):
    list_display = ('id', 'user', 'created')
    search_fields = ('username',)

which i also want to registered like this

site.register(Student, StudentAdmin)

But then i get the error that Student is already registered

Upvotes: 2

Views: 2942

Answers (3)

Arpit Singh
Arpit Singh

Reputation: 3467

Perhaps you can use proxy models Like..

class MyStudent(Student):
    class Meta:
        proxy=True

class MyStudentAdmin(ModelAdmin):
    list_display = ('id', 'user', 'created')
    search_fields = ('username',)

site.register(Student, ModelAdmin)
site.register(MyStudent, MyStudentAdmin)

Upvotes: 9

tuna
tuna

Reputation: 6351

First you have to unregister your register declarement

site.register(Student, ModelAdmin)

with

site.unregister(Student, ModelAdmin)

and then register second

site.register(Student,StudentAdmin)

You can not use both at the same time . (1 Model - 1 AdminModel)

Upvotes: -2

Thomas
Thomas

Reputation: 11888

No, you cannot register more than one ModelAdmin (sub)class for a single Model.

django.contrib.auth will raise an error if you attempt this.

Upvotes: -5

Related Questions