Reputation: 1153
I've a database of doctors. I want to be able to see in the admin panel under doctors who created a particular doctor entry. I've the following in my admin.py
class CustomUserAdmin(UserAdmin):
filter_horizontal = ('user_permissions', 'groups')
save_on_top = True
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'last_login', 'date_joined')
admin.site.register(User, CustomUserAdmin)
class DoctorAdmin(admin.ModelAdmin):
list_display = ('name', 'specialization', 'education1', 'clinic', 'submitted_on', 'rating', 'netlikes')
search_fields = ('name', 'id', 'specialization__name', 'clinic__name')
admin.site.register(Doctor, DoctorAdmin)
I want to have another column next to netlikes as 'submitted by' and would like to see the username of the person who created that doctor entry.
Upvotes: 1
Views: 38
Reputation: 4382
Your Doctor
model will need to have a field that stores this information, such as
submitted_by = ForeignKey(settings.AUTH_USER_MODEL)
You have to make sure to populate this information whenever you create a new instance of Doctor
, probably using request.user
. Then, in your ModelAdmin
, you can just add this field to list_display
.
Upvotes: 2