How to do it...

Follow these steps to enhance the User model in the accounts app:

  1. Add the avatar field and django-imagekit thumbnail specification to the User model:
# myproject/apps/accounts/models.pyimport osfrom imagekit.models import ImageSpecFieldfrom pilkit.processors import ResizeToFillfrom django.utils import timezone# …def upload_to(instance, filename):    now = timezone.now()    filename_base, filename_ext = os.path.splitext(filename)    return "users/{user_id}/{filename}{ext}".format(        user_id=instance.pk,        filename=now.strftime("%Y%m%d%H%M%S"),        ext=filename_ext.lower(),    )class User(AbstractUser):    # …    avatar = models.ImageField(_("Avatar"), upload_to=upload_to,      blank=True)    avatar_thumbnail = ImageSpecField(        source="avatar",        processors ...

Get Django 3 Web Development Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.