Add profile_pic

This commit is contained in:
2020-12-24 17:24:02 +01:00
parent 07fe1bc3ca
commit 35e0f912fe
2 changed files with 81 additions and 10 deletions

View File

@@ -6,15 +6,28 @@
database.
'''
import os
import uuid
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _
from lostplaces.models.abstract_models import Expireable
from easy_thumbnails.fields import ThumbnailerImageField
from easy_thumbnails.files import get_thumbnailer
def generate_profile_image_filename(instance, filename):
"""
Callback for generating filename for uploaded explorer profile images.
Returns filename as: explorer_pk-username.jpg
"""
return 'explorers/' + str(instance.explorer.pk) + '-' + str(instance.explorer.username) + '.' + filename.split('.')[-1]
class Explorer(models.Model):
"""
Profile that is linked to the a User.
@@ -26,6 +39,15 @@ class Explorer(models.Model):
on_delete=models.CASCADE,
related_name='explorer'
)
profile_image = ThumbnailerImageField(
blank=True,
null=True,
upload_to=generate_profile_image_filename,
resize_source=dict(size=(400, 400),
sharpen=True),
verbose_name=_('Profile image'),
help_text=_('Optional profile pic for display in explorer profile')
)
def __str__(self):
return self.user.username
@@ -58,4 +80,3 @@ class Voucher(Expireable):
def __str__(self):
return "Voucher " + str(self.code)