Move signal to it's own file.
This commit is contained in:
parent
f7f65dae68
commit
cf5cea2e52
3 changed files with 17 additions and 8 deletions
|
@ -3,3 +3,6 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
class ProfilesConfig(AppConfig):
|
class ProfilesConfig(AppConfig):
|
||||||
name = 'profiles'
|
name = 'profiles'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
from .signals import create_profile
|
||||||
|
|
|
@ -2,8 +2,6 @@ from django.conf import settings
|
||||||
from django.core.validators import (MaxLengthValidator, MinValueValidator,
|
from django.core.validators import (MaxLengthValidator, MinValueValidator,
|
||||||
MaxValueValidator)
|
MaxValueValidator)
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.signals import post_save
|
|
||||||
from django.dispatch import receiver
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from core.behaviors import Timestampable
|
from core.behaviors import Timestampable
|
||||||
|
@ -28,12 +26,6 @@ class RadioProfile(Timestampable, models.Model):
|
||||||
return "{}'s profile".format(self.user.get_username())
|
return "{}'s profile".format(self.user.get_username())
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
|
||||||
def create_profile(sender, instance, created, **kwargs):
|
|
||||||
if created:
|
|
||||||
profile, new = RadioProfile.objects.get_or_create(user=instance)
|
|
||||||
|
|
||||||
|
|
||||||
class Rating(Timestampable, models.Model):
|
class Rating(Timestampable, models.Model):
|
||||||
profile = models.ForeignKey(RadioProfile,
|
profile = models.ForeignKey(RadioProfile,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
|
14
savepointradio/profiles/signals.py
Normal file
14
savepointradio/profiles/signals.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from .models import RadioProfile
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
||||||
|
def create_profile(sender, instance, created, **kwargs):
|
||||||
|
"""
|
||||||
|
Create a profile object after a new user is created and link them.
|
||||||
|
"""
|
||||||
|
if created:
|
||||||
|
profile, new = RadioProfile.objects.get_or_create(user=instance)
|
Loading…
Reference in a new issue