[Fixed]-Access to user data from profile in admin.py

1👍

You cannot reach the object directly. Instead you’ll have to use a custom method. The following should get you started:

class ProfilAdmin(admin.ModelAdmin):
    list_display = ('get_username', )

    search_fields = ['user__username', ]

    def get_username(self, obj):
        return obj.user.username
    get_patient.short_description = 'User'
    get_patient.admin_order_field = 'user__username'

See also Django admin list_display property usage.

👤SaeX

Leave a comment