14 lines
386 B
Python
14 lines
386 B
Python
import uuid
|
|
|
|
from django.db.models.signals import post_save
|
|
from django.dispatch import receiver
|
|
|
|
from apps.users.models import User
|
|
|
|
|
|
@receiver(post_save, sender=User)
|
|
def ensure_username_on_registration(sender, instance, created, **kwargs):
|
|
if created and not instance.username:
|
|
instance.username = str(uuid.uuid4())[:10]
|
|
instance.save(update_fields=["username"])
|