I am trying to display an image from online source (e.g. facebook) which is not a field in the model in the User Change Form.
I can successfully display it in the user list page, or in a separate Model page, or in the add new user page, but I want to add this image to the existing user editing page below username and password fields.
class TestForm(forms.ModelForm):
class Meta:
model = User
fields = ('email', 'password')
@admin.register(User)
class UserAdmin(BaseUserAdmin):
form = TestForm
# ... attributes
Nothing happened even it's a test form with 2 defined model fields. I expected the page to be showing email and password only.
# User Model
def image(self):
return mark_safe('<img src="http://onlinesource.com/image.png" width=200 height=200 alt="image" />')
image.short_description = _('Image')
# admin.py
@admin.register(User)
class UserAdmin(BaseUserAdmin):
# ...
list_display = ('image',) # this works and you can see the image in list view page
fieldsets = (None, {"fields": ("image",)}) # this will throw error since `image` is not a field
This is basically to display image in the list view page. It can't be shown in single user page as image
is not a model field.