Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:10:48+00:00 2026-05-26T22:10:48+00:00

I have a new project on django, in which im using Grappelli and filebrowser,

  • 0

I have a new project on django, in which im using Grappelli and filebrowser, and I have extended the User to have a UserProfile related to it, my question is, how can I modify my code to be able to show on the UserProfile information of a user the profile picture uploaded, and also show it on the Users list?

This is my code now, I dont see any image on the admin!

Admin.py

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from models import UserProfile

class UserProfileInline(admin.StackedInline):
     model = UserProfile
     verbose_name_plural = 'User Profile'
     list_display = ('city', 'tel', 'description', 'image_thumbnail',)

class MyUserAdmin(UserAdmin):
    list_display = ('username','email','first_name','last_name','date_joined',
        'last_login','is_staff', 'is_active',)
    inlines = [ UserProfileInline ]


admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

Models.py

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.utils.translation import ugettext_lazy as _
from apps.common.utils.abstract_models import BaseModel
from apps.common.utils.model_utils import unique_slugify
from filebrowser.base import FileObject
from django.conf import settings

class UserProfile(BaseModel):
    user = models.OneToOneField(User, related_name="profile")
    city = models.CharField(_("City"), max_length=200)
    tel = models.CharField(_("Phone Number"), max_length=50, 
    help_text=_("(Area Code) (Your phone number)"))
    description = models.TextField(null=True, blank=True, 
        help_text = _("Small description about yourself."))
    photo = models.ImageField(max_length=255, upload_to="profiles/", 
        null=True, blank=True, default="img/default_profile_image.png")

    def image_thumbnail(self):
        if self.photo:
             return u'<img src="%s" width="80" height="80" />' % self.photo.version(ADMIN_THUMBNAIL).url
        return u'<img src="/site_media/%s" width="80" height="80" />' % settings.DEFAULT_PROFILE_IMAGE

     image_thumbnail.allow_tags = True

    def __unicode__(self):
        if self.user.first_name or self.user.last_name:
            return "%s %s" % (self.user.first_name, self.user.last_name)
        else:
            return self.user.username
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:10:48+00:00Added an answer on May 26, 2026 at 10:10 pm

    Well I got it, first I wanted to show the image chosen on the UserProfile inline section of the user model for the admin and also on the change list of the admin so heres what I

    I changed the models.ImageField to sorl ImageField on the model.py of User profile like this

    from sorl.thumbnail import ImageField
    class UserProfile(BaseModel):
    [...]
        photo = ImageField(max_length=255, upload_to="profiles/", 
            null=True, blank=True, default="img/default_profile_image.png")
    

    Then on the admin all I had to do was add sorl’s AdminImageMixin on the UserProfileInline class, like this:

    from sorl.thumbnail.admin import AdminImageMixin
    
    class UserProfileInline(AdminImageMixin, admin.StackedInline):
        model = UserProfile
        verbose_name_plural = 'User Profile'
    

    And that way you get an image on the UserProfile Inline section on the admin for that user, now for the change_list.

    For the change list I had to do a small callable function inside the admin.py file on the UserAdmin class, heres what I did, using sorl’s get_thumbnail:

    from sorl.thumbnail import get_thumbnail
    
    class MyUserAdmin(UserAdmin):
    
        def image_thumbnail(self, obj):
            im = get_thumbnail(obj.get_profile().photo, '80x80', quality=99)
            return u"<img src='/site_media/%s' />" % im
        image_thumbnail.allow_tags = True
    
        list_display = ('image_thumbnail', 'username','email','first_name','last_name','date_joined',
        'last_login','is_staff', 'is_active',)
    

    And now I have a change list image of the user profile and also on the UserProfile Inline section.

    Hope this works for everyone out there… and thanks @pastylegs for your previous answer!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new project which simply put, is an attempt to formalize the
I have to start a new project where user authentication/management will be required. A
I have just started a new project, and I am using the Delphi 2009
I'm working on a new project and I'm using the repository pattern, I have
This is my first project in django and im using photologue for gallery, which
I have a Django project in Eclipse PyDev. I have a file views.py which
Recently, I have become increasingly familiar with Django. I have a new project that
I am new to Django and have started working on a mature Django project.
I have a django project that I have been using for a while, but
I have started a new mvc project and clicked on project\properties\web - use local

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.