Inital commit
This commit is contained in:
15
splitchat/core/signals.py
Normal file
15
splitchat/core/signals.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.db.models.signals import post_save
|
||||
from django.contrib.auth.models import User
|
||||
from django.dispatch import receiver
|
||||
from .models import UserProfile
|
||||
|
||||
AVATAR_COLORS = [
|
||||
'#6366f1', '#8b5cf6', '#ec4899', '#f43f5e',
|
||||
'#f97316', '#eab308', '#22c55e', '#14b8a6', '#3b82f6'
|
||||
]
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
color = AVATAR_COLORS[instance.id % len(AVATAR_COLORS)]
|
||||
UserProfile.objects.get_or_create(user=instance, defaults={'avatar_color': color})
|
||||
Reference in New Issue
Block a user