Move signal to it's own file.

This commit is contained in:
Josh Washburne 2018-01-19 11:26:14 -05:00
parent f7f65dae68
commit cf5cea2e52
3 changed files with 17 additions and 8 deletions

View file

@ -3,3 +3,6 @@ from django.apps import AppConfig
class ProfilesConfig(AppConfig):
name = 'profiles'
def ready(self):
from .signals import create_profile

View file

@ -2,8 +2,6 @@ from django.conf import settings
from django.core.validators import (MaxLengthValidator, MinValueValidator,
MaxValueValidator)
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 core.behaviors import Timestampable
@ -28,12 +26,6 @@ class RadioProfile(Timestampable, models.Model):
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):
profile = models.ForeignKey(RadioProfile,
on_delete=models.CASCADE,

View 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)