How to hide fields that belong to the model I'm inheriting from in django admin panel

I have these 2 models in my models.py

class Student(AbstractBaseUser):
    date_of_birth = models.DateField(null=True)
    phone_number = PhoneNumberField(null=True)

class Teacher(Student):
    bio = models.TextField(null=True)
    image = CompressedImageField(null=True, blank=True, default="default.png")
    student = models.ForeignKey(Student, on_delete=models.SET_NULL, null=True)

Now in admin panel when i go to edit the Teacher instance I display only bio image and student. The issue is that also display those fields when I try to edit Teacher instance but entering from Student model. So is there a way for that?

P.S the models and fields may not make sense because they are examples.

Use ModelAdmin.fields or ModelAdmin.exclude to control which fields you want to include or exclude in the admin site form.

from django.contrib import admin

class TeacherAdmin(admin.ModelAdmin):
    exclude = ("date_of_birth", "phone_number")

And register it like so

admin.site.register(Teacher, TeacherAdmin)
Back to Top