Open wrench1815 opened 3 years ago
Hmm, it should have worked with "user_avatar": "profile_image"
Though this feature isn't used too often, and could do with better testing.
The code you referenced should pull the given attribute off of the implemented user model, and get its URL (assumes it's an ImageField)
It may be that it's not getting your custom user model some how, and is looking for the attribute on the default auth.user model ?
It may be that it's not getting your custom user model some how, and is looking for the attribute on the default auth.user model ?
Yes that's what happening. It's Trying to look for that field on default auth.user while its on another another and its like auth.user.profile and the profile model has that imagefield for avatar.
I have worked on and merged in https://github.com/farridav/django-jazzmin/pull/338
are you able to install jazzmin from master pip install https://github.com/farridav/django-jazzmin/archive/master.zip
and see if it fixes your problem ?
My Apologies for the delay in reply> And yes it works now. Thanks for such a fast fix.
Hi There :)
I ran into this problem and was guided to this page by chance.
To solve this problem, you only need to enter the field that contains the user's avatar photo.
Jazmin automatically recognizes the user's model and you only need to introduce that field to it .
for example:
My user model :
class User(AbstractUser):
avatar = models.ImageField(upload_to='profile/')
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
my jazzmin settings :
JAZZMIN_SETTINGS = {
....
"user_avatar": "avatar",
....
}
class User(AbstractUser):
def avatar(self):
return self.userphoto_set.last().image.url
class UserPhoto(Model):
user = ForeignKey('apps.User', CASCADE)
image = ResizedImageField(size=[736, 736], crop=['middle', 'center'], upload_to='users', blank=True, null=True)
If you have this type of code, you can easily get user image and show it in admin panel. In next picture you can see it result:
il change que comme ca il voulait pas s affihcher
"user_avatar": "photo", class Profile(models.Model): account = models.OneToOneField(User, on_delete=models.CASCADE) phone=models.CharField(max_length=16) photo = models.ImageField(upload_to='user_photos/', null=True, blank=True)
def __str__(self) -> str:
return self.account.username
aider moi svp
meme si je change ca "user_avatar": "fas fa-users-cog", il rest comme ca
I've created a Model named
Profile
which hasprofile_image
field on it. I use this extended model to set User Profile Images. Which can be accessed inUser
Model byprofile.profile_image
. But in Jazzmin settings if i set"user_avatar": "profile"
, It says there is no attributeurl
onUser
model. So after digging in Jazzmin project repo, i found this Templatetag which handles the fetching of User Avatar Image.Is it possible to override it so I can return
avatar_field.profile_image.url
instead? or is there a way to reference the Extended Model field? Or maybe I'm missing something? I did tried"user_avatar": "profile__profile_image"
and"user_avatar": "profile_image"
and"user_avatar": "profile.profile_image"
just in case, but it didn't worked.Thanks in Advance.