I have used a custom user model to overwrite username with email-id. Now I want to add an extra field that profiles pictures. I tried extending the model in models.py with the OnetoOne relationship. It works but as I am passing forms to update and create views (Class-based views) to update and create.
is there any way to add a profile picture field without creating a model with the OnetoOne relationship?
SOLUTION:
I was missing enctype="multipart/form-data" in form tags
i think this will helps you, check my github code... i`m using image field in User model.
https://github.com/shotttik/carwashProject/blob/master/user/models.py
#models.py
class UserManager(BaseUserManager):
....
def create_superuser(self, email=None, password=None, **extra_fields):
extra_fields.setdefault('image', "default/image/path")
...
class User(AbstractUser):
....
image = models.ImageField(upload_to='images/')
then you can add image field into forms.py
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.