2

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

user2330497
  • 419
  • 1
  • 7
  • 11
  • Why do you still want to do `site.register(Student, ModelAdmin)` if `StudentAdmin` does the same thing, only customized? – Snakes and Coffee May 10 '13 at 06:04
  • Actually i am overiding some more methods and changing some views completly. so if someone type `/student` then it goes to default chnagelist page but when i type '/mystudent' then i will be calling the custom chnagelist view with different stuff in it – user2330497 May 10 '13 at 06:11
  • Is there any reason you can't use your subclass for both types of views using GET parameters? – Thomas May 10 '13 at 06:23
  • Possible duplicate of [Multiple ModelAdmins/views for same model in Django admin](https://stackoverflow.com/questions/2223375/multiple-modeladmins-views-for-same-model-in-django-admin) – Chillar Anand Jun 21 '19 at 03:51

3 Answers3

9

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)
Arpit Singh
  • 3,387
  • 2
  • 17
  • 11
-2

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)

tuna
  • 6,211
  • 11
  • 43
  • 63
-5

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.

Thomas
  • 11,757
  • 4
  • 41
  • 57