Adding Profile Picture To Django User
I'm trying to follow this post to associate a profile picture to a user in Django. I have the following model class MyUser(AbstractBaseUser): ''' Custom user class. '''
Solution 1:
It's not good idea to set a Boolean for checking whether the user has an avatar. You have two options: you can play with the empty url in your template or define a method to set user avatar in models.py
Option 1: in your template
{% if user.avatar == None %}
<img src="DEFAULT_IMAGE" />
{% else %}
<img src="user.avatar"/>
{% endif %}
Option 2: in your models
defset_avatar(self):
_avatar = self.avatar
ifnot_avatar:self.avatar="path/to/default/avatar.png"
Also, if your user never gets saved, if because you are calling save method with commit=False
.
Post a Comment for "Adding Profile Picture To Django User"