add: profile avatar

This commit is contained in:
2023-12-06 15:19:41 +01:00
parent 910644a804
commit 9b6c5547f0
16 changed files with 141 additions and 37 deletions

View File

@ -3,11 +3,15 @@ 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.conf import settings
def upload_to(instance, filename: str):
return f"./profiles/static/avatars/{instance.pk}.{filename.split('.')[1]}"
# Create your models here.
class ProfileModel(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=40)
avatar_url = models.ImageField(upload_to=upload_to, default="../static/avatars/default.avif") #blank=True, null=True)
@receiver(post_save, sender=User)
def on_user_created(sender, instance, created, **kwargs):