mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 13:34:08 +01:00
Use signal to create UserStats Instead
This commit is contained in:
parent
0c256bf003
commit
89fb618698
@ -4,3 +4,6 @@ from django.apps import AppConfig
|
||||
class UsersConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'users'
|
||||
|
||||
def ready(self):
|
||||
import users.signals
|
||||
@ -31,10 +31,6 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
USERNAME_FIELD = 'email'
|
||||
REQUIRED_FIELDS = ['username', 'first_name']
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
UserStats.objects.get_or_create(user=self)
|
||||
super(CustomUser, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
# String representation of the user
|
||||
return self.username
|
||||
|
||||
9
backend/users/signals.py
Normal file
9
backend/users/signals.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from users.models import CustomUser, UserStats
|
||||
|
||||
@receiver(post_save, sender=CustomUser)
|
||||
def create_user_stats(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
UserStats.objects.create(user=instance)
|
||||
Loading…
Reference in New Issue
Block a user