hide particular attribute in django admin
To hide a particular attribute in Django admin, you can follow these steps:
- Open the appropriate admin.py file for the app in which the model is defined.
- Import the model for which you want to hide the attribute.
- Create a new class that inherits from the model's default admin class.
- Inside the new class, define a list variable called
exclude
and add the name of the attribute you want to hide to the list. - Register the model with the new admin class using the
admin.site.register()
method.
Here is an example:
from django.contrib import admin
from .models import YourModel
class YourModelAdmin(admin.ModelAdmin):
exclude = ['attribute_to_hide']
admin.site.register(YourModel, YourModelAdmin)
In this example, we import the YourModel
model and create a new class called YourModelAdmin
that inherits from admin.ModelAdmin
. We define the exclude
variable and add the name of the attribute we want to hide to the list. Finally, we register the YourModel
model with the YourModelAdmin
class using the admin.site.register()
method.
By following these steps, the attribute specified in the exclude
list will be hidden in the Django admin interface.