4👍
✅
Instead of doing it in __str__
method, you can specify which fields to display in the list in admin.
class MyModelAdmin(admin.ModelAdmin):
def get_list_display(self, request):
if request.user.is_superuser:
return ('title' , 'created_by')
else:
return ('title',)
admin.site.register(MyModel, MyModelAdmin)
and then update your __str__
method to return just the title.
Source:stackexchange.com